nateshmbhat / pyttsx3

Offline Text To Speech synthesis for python
Mozilla Public License 2.0
2.08k stars 327 forks source link

Pyttsx3. Only Speaks Once #131

Open hankp46 opened 4 years ago

hankp46 commented 4 years ago

When running the following program:

import multiprocessing import pyttsx3 from multiprocessing import Process

class _TTS:

def init(self): self.engine = pyttsx3.init('espeak') self.engine.setProperty('rate', 175)

def start(self,text): self.engine.say(text) self.engine.runAndWait()

def Speakit(words): print('running Speakit')

tts = _TTS()
tts.start(words)
del(tts)

def testing(n): print(n) if n == 0: words = 'Argument is zero' Speakit(words) print(words) else: words = 'Argument is not zero' Speakit(words) print(words)

if name=="main": words = 'start' Speakit(words) p1=Process(target=testing,args=(0,)) p1.start() p1.join() p2=Process(target=testing,args=(5,)) p2.start() p2.join() print("We're done") If I comment out the Speakit in the main, the script run correctly, speaking what prints out

Watson $ python3 mp2.py 0 running Speakit Argument is zero 5 running Speakit Argument is not zero We're done It I don't comment out the Speakit in the main, the script will just speak the "Start" word and then not speak again and just hangs

python3 mp2.py running Speakit 0 running Speakit Don't understand why

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.91. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

rakeshsagalagatte commented 4 years ago

@hankp46 you are not calling testing function correctly in a Process , That is , p1=Process(target=testing,args=(0,)) which is replaced by p1=Process(target=testing(4),args=(0,)) . It's not a bug.

import multiprocessing
import pyttsx3
from multiprocessing import Process

class _TTS:
    def __init__(self):
        self.engine = pyttsx3.init('espeak')
        self.engine.setProperty('rate', 175)

    def start(self,text_):
        self.engine.say(text_)
        self.engine.runAndWait()

def Speakit(words):
    print('running Speakit')
    tts = _TTS()
    tts.start(words)
    del(tts)

def testing(n):
    print(n)
    if n == 0:
        words = 'Argument is zero'
        Speakit(words)
        print(words)
    else:
        words = 'Argument is not zero'
        Speakit(words)
        print(words)

if __name__=="__main__":
    words = 'start'
    Speakit(words)
    p1=Process(target=testing(4),args=(0,))
    p1.start()
    p1.join()
    p2=Process(target=testing(0),args=(5,))
    p2.start()
    p2.join()
    print("We're done")
hankp46 commented 4 years ago

Rakesh. Yes, that solved the problem. But I have a question hopefully you can answer. In my original script why did commenting out the Speakit in the main function seem to make it work properly. Thank you for your help!

rakeshsagalagatte commented 4 years ago

If the above code is your original script , It works fine or above one is not your original script: can you share error what you are getting , It will help me .

hankp46 commented 4 years ago

The first script in the issue is the original script. It I don't comment out the Speakit in the main, the script will just speak the "Start" word and then not speak again and just hangs in the Speakit function when 0 is passed to the testing function. running Speakit (wiords = Start) 0 running Speakit (when 0 is passed to testing) then Speakit is called, then it hangs).

Hope this makes sense

rakeshsagalagatte commented 4 years ago

@hankp46 It's working on my system , you can replace your code by my code what i mention in the above comment .