Is there a way to hack the speech module to save audio files instead of directly playing them to the device speakers?
Forum Archive
Save audio files from speech
It is possible with some objcutil code. And @omz made a ctypes version. Give me some time and i will make it :-)
Here it is :-)
https://gist.github.com/8b21ea99721ff2bb3606
What did those deleted posts say?
I misunderstood the problem and posted a script that has nothing to do with saving a file containing a text to speech audio 😊
i think this can be done with objc...
Yes. Its easy to make a text to speech. What is difficult is saving the audio data in a file
i was thinking this would be possible with Audio Units, but looking closer, it is not clear that AVSpeechUtterances go through Audio Units.
Another possibility is to use one of the various free online tts tools/demos, and download the resulting mp3. This could possibly be done using requests if tou wantthis to be dynamic, or if you are just looking for a sound file for static text, you could just do it manually.
That's great news, @JonB. I'll consider this. Is this possible on iOS?
Unfortunately, the code you linked to is Mac-specific and doesn't work on iOS because the NSSpeechSynthesizer class doesn't exist there. There's only AVSpeechSynthesizer, and from what I can see, it doesn't support any way of saving synthesized speech to disk, apparently not even via private APIs.
Ok. Thanks for your help everybody anyway
Look at omz's Audio Recorder.py,
https://gist.github.com/omz/9882a00abf59c6009fa4
copy and save as audio.py
Change lines 63-74 to:
if started_recording:
import speech, sound
speech.say('Whatever you want it to say')
#time.sleep(however many seconds long is the recording)
#im not sure if say() is asynchronous, if so, uncomment last line
msg(recorder, None, 'stop')
msg(recorder, None, 'release')
#sound.play_effect(os.abspath('Recording.m4a'))
#uncomment last line if you want it to play again