convert text to speech online free code example

Example 1: text to speech

import pyttsx3
engine = pyttsx3.init()
engine.say("")
engine.runAndWait()

Example 2: speech to text

import speech_recognition as sr
def mycommand():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("listening....")
        r.pause_threshold =  1
        audio = r.listen(source)
query = mycommand()
print(query)
#prints whatever you said

Example 3: text to speech online

import pyttsx3

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
# you can use print(voices) to see how many voices you have installed
# print(voices[0].id)
# print(voices[1].id)
# print(voices[2].id)
print(voices)
engine.setProperty('voices', voices[0].id)

def speak(audio):
  	print(audio)
    engine.say(audio)
    engine.runAndWait()
    
speak('Hello')

# prints hello and says it

Example 4: text to speech

import pyttsx3
engine = pyttsx3.init()
engine.say("write  here what you want to speak")
engine.runAndWait()