Python Forum
pyttsx3 cuts off when run from py file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyttsx3 cuts off when run from py file
#1
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)
Reply
#2
I tried it and it ran without error

I then retried from shell and get no errors:
Reply
#3
when i run from terminal there are no errors but the voice is cut off before it finishes
Reply
#4
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.
Reply
#5
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Controlling text-to-speech pauses with pyttsx3 pmac1300 4 4,482 Mar-14-2022, 06:47 AM
Last Post: Coricoco_fr
  pyttsx3 cutting off last word Extra 3 2,919 Feb-28-2022, 11:20 PM
Last Post: BashBedlam
  pyttsx3 problem Tyrel 0 1,118 Feb-05-2022, 08:53 AM
Last Post: Tyrel
  Know when the pyttsx3 engine stops talking UsualCoder 3 3,239 Aug-29-2021, 11:08 PM
Last Post: snippsat
  working with pyttsx3 gr3yali3n 0 1,613 Nov-24-2020, 09:40 AM
Last Post: gr3yali3n

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020