Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Male Voice Not Working #299

Closed
Lonehunter16 opened this issue Dec 6, 2023 · 3 comments
Closed

Male Voice Not Working #299

Lonehunter16 opened this issue Dec 6, 2023 · 3 comments
Labels
Needs-Checking Possibly outdated. Needs checking with current latest

Comments

@Lonehunter16
Copy link

My male voice sounds like a weird version of the female voice. Here's my code:

import pyttsx3
import pyttsx3.voice

class VoiceEngine(object):

    voiceDict = {"male": 0, "female": 1}

    def __init__(self, voice: str="female", speed: int=144):
        """
        Initialize a VoiceEngine object.
        :param voice: 'male' or 'female'
        """

        try:
            self.voice = VoiceEngine.voiceDict[voice]
            self.speed = speed
        except:
            self.voice = 1
            self.speed = 144
            print("Defaulting to female voice due to an error in the input.")
        self.engine = pyttsx3.init("sapi5")
        voices = self.engine.getProperty("voices")
        self.engine.setProperty("voice", voices[self.voice].id)
        self.engine.setProperty("rate", self.speed)

    def speak(self, text: str):
        self.engine.say(text)
        self.engine.runAndWait()

    def set_speed(self, speed: int):
        self.speed = speed
        self.engine.setProperty("rate", self.speed)

    def set_voice(self, id):
        self.voice = id
        self.engine.setProperty("voice", self.voice)

if __name__ == '__main__':
    voice_engine = VoiceEngine("male")
    voice_engine.set_speed(200)
    voices = pyttsx3.init()
    male_voice = pyttsx3.voice.Voice(2, name="male", languages=["english"], gender="male")
    voices = voices.getProperty("voices")
    voice_engine.set_voice(2)
    voice_engine.speak("""When a doctor doctors a doctor, does the doctor doing the doctoring doctor as the doctor being doctored wants to be doctored or does the doctor doing the doctoring doctor as he wants to doctor?""")
@willwade
Copy link
Collaborator

This is wierd. I imagine you were using espeak (Linux). I realise it was a long time ago but if you get a chance I’d like to know

@willwade willwade added the Needs-Checking Possibly outdated. Needs checking with current latest label Oct 18, 2024
@willwade
Copy link
Collaborator

This issue is bothering me.

For a start - male or female voices dont make a jot of difference in espeak. I think i need to look into getVoices for this

also though - your string

Something is really odd about it

voice_engine.speak("""When a doctor doctors a doctor, does the doctor doing the doctoring doctor as the doctor being doctored wants to be doctored or does the doctor doing the doctoring doctor as he wants to doctor?""")

Just wont work standalone

If we remove the comma and ? we get somewhere - but its something in this last part "doctor doing the doctoring doctor as he wants to doctor" that is causing it to crash and burn

@willwade
Copy link
Collaborator

update - my fixes in most recent PR seems to have cleared the speking bug. I think it was to do with using END not MSG Terminator - in espeak. something in that sentence was causing a early end.. closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Checking Possibly outdated. Needs checking with current latest
Projects
None yet
Development

No branches or pull requests

2 participants