0

When I use pyttsx3 to speak only female voice how can I change it to male rate and frequency doesn't work. please update this code -

import speech_recognition as sr
import pyttsx3

listener = sr.Recognizer()
engine = pyttsx3.init()
engine.say('Hello, I am assistant vocal personnel virtuel')
engine.say('what can i help you with')
engine.runAndWait()
try:
    with sr.Microphone() as source:
        print('listening...')
        voice = listener.listen(source)
        command = listener.recognize_google(voice)
        command = command.lower()
        if 'hey vocal' in command:
            print(command)
except:
    pass

I am building a voice assistant.

buhtz
  • 10,774
  • 18
  • 76
  • 149
Aniket M
  • 31
  • 5

1 Answers1

0

This small demo should help you.

It will speak all available names while function change_voice will give you control over the rate and volume of each voice.

import pyttsx3

engine = pyttsx3.init()
# return a list of all voices
voices = engine.getProperty('voices')
engine.runAndWait()

def change_voice(indx, rate = 120, volume = 0.5):

    idname = voices[ indx ].id
    engine.setProperty('voice', idname)
    engine.setProperty('rate', rate)
    engine.setProperty('volume', volume)
    engine.runAndWait()

print(f"Found {len(voices)} voices")

# enunciate all available names
for indx, v in enumerate(voices):
    change_voice(indx, rate = 140, volume = 1)
    print(f"I am {v.name}")
    engine.say(f"I am {v.name}")
    engine.runAndWait()
Derek
  • 1,916
  • 2
  • 5
  • 15