I think I had the code below working a while ago, but today it isn't working - any idea on the possible cause & solution?
#! /usr/local/bin/python3
import soundfile as sf
import pyttsx3
engine = pyttsx3.init() # object creation
voices = engine.getProperty('voices')
engine.setProperty('voice','com.apple.speech.synthesis.voice.samantha')
#engine.say('This is a longer test to see how it converts')
# The line above does work, so all good so far.
engine.save_to_file('This is a longer test to see how it converts', 'test.aiff')
engine.runAndWait()
# The code above does create the audio file, but it won't read/play - see output below
data,samplerate = sf.read('test.aiff')
print(samplerate)
sf.write('test.wav',data,samplerate)
data,samplerate = sf.read('test.wav')
print(samplerate)
Here is the output and trying to play the audio file from the command line:
$ python3 test2.py
Traceback (most recent call last):
File "/Users/rpm/test2.py", line 25, in <module>
data,samplerate = sf.read('test.aiff')
File "/usr/local/lib/python3.9/site-packages/soundfile.py", line 256, in read
with SoundFile(file, 'r', samplerate, channels,
File "/usr/local/lib/python3.9/site-packages/soundfile.py", line 629, in __init__
self._file = self._open(file, mode_int, closefd)
File "/usr/local/lib/python3.9/site-packages/soundfile.py", line 1183, in _open
_error_check(_snd.sf_error(file_ptr),
File "/usr/local/lib/python3.9/site-packages/soundfile.py", line 1357, in _error_check
raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening 'test.aiff': Format not recognised.
$ afplay test.aiff
Unspecified exception
I think I had the code below working a while ago, but today it isn't working - any idea on the possible cause & solution?
Here is the output and trying to play the audio file from the command line: