Python 3.4 - Text to Speech with SAPI

前端 未结 2 1781
猫巷女王i
猫巷女王i 2020-12-04 02:43

I was trying to use this code to convert text to speech with Python 3.4, but since my computer\'s main language is not English (I\'m using Win7x64) the voice and the accent

2条回答
  •  悲&欢浪女
    2020-12-04 03:00

    This works in python.

    Feel free to make it more elegant.

    import win32com.client as wincl
    
    speaker_number = 1
    spk = wincl.Dispatch("SAPI.SpVoice")
    vcs = spk.GetVoices()
    SVSFlag = 11
    print(vcs.Item (speaker_number) .GetAttribute ("Name")) # speaker name
    spk.Voice
    spk.SetVoice(vcs.Item(speaker_number)) # set voice (see Windows Text-to-Speech settings)
    spk.Speak("Hello, it works!")
    

    This should also provide a general idea of how to translate from the SDK examples.

提交回复
热议问题