Hi, I’m using gTTS to create the voice .wav file. key lines are as follows:
tts = gTTS(text=text,tld="co.uk", lang=lang_code, slow=False)
audio_duration =len(text)*0.2
engine = pyttsx3.init()
voices = engine.getProperty('voices')
...
engine.setProperty('voice', voice.id)
rate = engine.getProperty('rate')
engine.setProperty('rate', rate-35)
engine.setProperty('volume', vol)
engine.save_to_file(text , temporaryttsvoicefile) ******************
...
engine.runAndWait()
The line with the **** is where the file is saved (temporaryttsvoicefile is a path to a temp file.wav). There is some surrounding code choosing the voice/volume etc. text is a ‘quote’ of 3-10 sentences. Creating an audio file of 20-30 secs ish.
Prior to this I have run.
file_to_delete = Path(temporaryttsvoicefile)
file_to_delete.unlink()…to make sure the existing wav file doesn’t accidently get used again.
Then I pick up the file (or sometimes I do, depending on the error) with the following code.
audio_clip = AudioFileClip(temporaryttsvoicefile, buffersize=math.inf)
*****************problem line above********************
Read_clip =(audio_clip).set_start(vid_read_time_start)
Sound_clip =(AudioFileClip(full_audio_path)
.set_duration(vid_len).audio_fadeout(0.25).set_start(0.0))
As you see I’m pulling the tempttsvoicefile wav and using movie py to create a sound clip ( pulling in some music mp3s.) I then do some processing on the volumes etc to make sure the tts clip can be heard and composite them together.
The******** is the problem line where I get 'can’t find file error). The buffersize=math.inf doesn’t really do anything. I added that just in case it may help but it didn’t change anything). I have tried surrounding virtually every line above with a delay of up to 30 secs but the compiler/interpreter doesn’t heed these and I get the error anyway. (I guess the compiler/interpreterr does heed them but adds them for my benefit, in the background it races ahead and tries to execute the problem line. Hope this helps.