The problem background

The main, is to do something romantic, in fact, is a part of the confession, and the built-in voice is not good, Huihui is ok, recently found a Edge xiaoxiao voice really sweet, love love

The main use of win32com.client class

The core code

speak_out = win32com.client.Dispatch('SAPI.SPVOICE') 
speak_out.Speak("What you're going to read.")
Copy the code
import win32com.client
import time

def speak(goalStr) :
    # Dispatch("APPs") requires the app to register for the COM service, and APPs is the registered name
    speak_out = win32com.client.Dispatch('SAPI.SPVOICE')  # Connect to the sapi.spvoice COM service
    value = goalStr.split(', ')
    for  value_str in value :
        speak_out.Speak(value_str)
        time.sleep(1)

if __name__ == '__main__':
    strValue ="The weather in Kunming is as follows, Date: August 18 (Tuesday), Weather: Rain, Temperature: 20℃, PM2.5: 20, relative humidity: 92%"
    speak(strValue)
Copy the code

Or use the PyTTSX3 library

The core code

    engine = pyttsx3.init()        # initialization
    engine.say("What you're going to read.")    The default text data to read
    engine.runAndWait()            # Read the sound
Copy the code
import pyttsx3

def speak(goalStr) :
    engine = pyttsx3.init()   # initialization
    engine.setProperty('voice'."com.apple.speech.synthesis.voice.sin-ji")  # set the pronunciation person, but my computer doesn't seem to be working
    # engine.setProperty('voice', "com.apple.speech.synthesis.voice.mei-jia")  
    rate = engine.getProperty('rate')  # Change speed range from 0 to 200. Default is 200
    engine.setProperty('rate', rate-40)
    engine.setProperty('volume'.0.7)  Set volume range to 0.0-1.0 default is 1.0
    engine.say(goalStr)   The default text data to read
    engine.runAndWait()   # Read the sound

if __name__ == '__main__':
    strValue ="The weather in Kunming is as follows: Date: August 18 (Tuesday), Weather: Rain, Temperature: 20℃, PM2.5: 20, relative humidity: 92%"
    speak(strValue)
Copy the code