Recording synthesized text-to-speech to a file in Python

前端 未结 5 402
小蘑菇
小蘑菇 2020-12-16 20:03

I am attempting to find a way to take synthesized speech and record it to an audio file. I am currently using pyttsx as my text-to-speech library, but there isn\'t a mechani

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 20:32

    You can call espeak with the -w argument using subprocess.

    import subprocess
    
    def textToWav(text,file_name):
       subprocess.call(["espeak", "-w"+file_name+".wav", text])
    
    textToWav('hello world','hello')
    

    This will write file_name.wav without reading out loud. If your text is in a file (e.g. text.txt) you need to call espeak with the -f parameter ("-f"+text). I'd recommend reading the espeak man pages to see all the options you have.

    Hope this helps.

提交回复
热议问题