Re: Python how to get the raw audio data from SAPI?

Try this:
from win32com.client.gencache import EnsureDispatch
import winsound
from wave import Wave_write
from io import BytesIO
voice=EnsureDispatch("SAPI.SPVoice")

while True:
    text=input("Enter text to speak")
    stream=EnsureDispatch("SAPI.SPMemoryStream")
    stream.Format.Type=34 #    SAFT44kHz16BitMono = 34
    voice.AudioOutputStream=stream
    voice.Speak(text)
    bytereader=BytesIO()

    wavefile=Wave_write(bytereader)
    wavefile.setnchannels(1)
    wavefile.setsampwidth(2)
    wavefile.setframerate(44100)
    wavefile.writeframes(stream.GetData().tobytes())
    data="" />    while data[0]==0: data="" />    winsound.PlaySound(data, winsound.SND_MEMORY)
    stream.SetData(0)



Just note, it will block until it's finished speaking since it's a demo. Also, I'm just excluding 0s for now, still need to look at a noise gate.
Also note that Microsoft Anna may not be that laggy. You'd have to try a different voice in order to get a speedup I guess.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : keithwipf1 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : philip_bennefall via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : keithwipf1 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ambro86 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : philip_bennefall via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : keithwipf1 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ambro86 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ambro86 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : keithwipf1 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : philip_bennefall via Audiogames-reflector

Reply via email to