Python Forum
pyttsx3 cuts off when run from py file - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: pyttsx3 cuts off when run from py file (/thread-14545.html)



pyttsx3 cuts off when run from py file - duelistjp - Dec-05-2018

i'm using pyttsx3 on a raspberry pi running raspbian which is debian linux to read out the current time and date. this is a simple test of the module before i try implementing reading out a timer in a larger project but i'm already running into a curious issue. when i run the py file the voice is cut off partway through when it starts reading the minutes. the exact same lines copied into the interactive python shell run fine. I am running from bash and have no gui. why does it work one way but not the other? and how do i get it to read properly. the py file is below

import datetime
import pyttsx3
now=datetime.datetime.now()
datestring= "The Current time is " + str(now.hour) + " " +str(now.minute) + \
            " and " + str(now.second) + " seconds on " + str(now.month) + \
            " " + str(now.day) + " " + str(now.year)
engine=pyttsx3.init()
engine.setProperty('rate',100)
engine.setProperty('volume',1)
engine.say(datestring)
engine.runAndWait()
print(datestring)



RE: pyttsx3 cuts off when run from py file - Larz60+ - Dec-05-2018

I tried it and it ran without error

I then retried from shell and get no errors:


RE: pyttsx3 cuts off when run from py file - duelistjp - Dec-05-2018

when i run from terminal there are no errors but the voice is cut off before it finishes


RE: pyttsx3 cuts off when run from py file - Larz60+ - Dec-06-2018

It finishes properly when I run it using python 3.7.1
Which version of python are you using?
You can probably ass a space at the end of your sentence ans fake it out.


RE: pyttsx3 cuts off when run from py file - DrNerdly118 - Dec-20-2018

I would recommend trying this as it works fine for me

import pyttsx

x = pyttsx.init()

def say(text):  #variabe name shortcut
    k.say(text)
    k.runAndWait()



    
say('hello there fellow python user')
although this doesn't work on my current desktop, this has worked on previous devices and the voice duration is perfectly fine

for any further information, you could use the package site for further instructions during use