Here is a little program which record the text to a wave file. I have tested the similar Python code
import winim/com
#~ from comtypes.gen import SpeechLib
var obj = CreateObject("SAPI.SpVoice")
obj.speak "Nim is a statically typed, imperative programming language."
var stream = CreateObject("Sapi.SpFileStream")
#~ stream.Open "r:/record.wav", SpeechLib.SSFMCreateForWrite, False
stream.Open r"r:\record.wav", 3, False
var temp_stream = obj.AudioOutputStream
obj.AudioOutputStream = stream
obj.speak("Hello World")
obj.WaitUntilDone(-1)
stream.Close()
obj.AudioOutputStream = temp_stream
question 1: what can we do the pyhon code from comtypes.gen import SpeechLib in Nim? I have tried obj.SSFMCreateForWrite, but it is wrong:
Error: unhandled exception: unsupported method: SSFMCreateForWrite [COMError]
question 2: when the above program runs, it fails and says
Error: unhandled exception: invoke method failed: AudioOutputStream [COMError]
so any fix? Thanks
Your question is quite old, but this works
var ttsStream = CreateObject("SAPI.SpFileStream")
ttsStream.Open("nimtts.wav", 3) # 3 is Create File (overwrites existing)
var ttswav = CreateObject("SAPI.SpVoice")
ttswav.setRef("AudioOutputStream", ttsStream)
ttswav.speak "Nim, Windows text to speech test to a wav file", 3
# wait for tts to wav to finish, but not longer than 10 seconds
# note that output to wav is much much faster than actually 'speaking' to audio device
ttswav.WaitUntilDone(10000)
ttsStream.Close()