Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
gTTS Input non responsive
#1
in this particular module, after successfully installing the pip files for the required input, the Google Text to Speech element is non responsive and disallows my module from running. I was wondering if I could get some help on this issue, in order for me to continue working towards the modules completion



from gtts import gTTS
import speech_recognition as sr
import os
import webbrowser
import smtplib
def talkToMe(audio):
    print(audio)
    tts = gTTS(text=audio, lang='en')
    tts.save('audio.mp3')
    os.system('mpg123 audio.mp3')
#listens for users commands

def myCommand():

    r = sr.recognizer()

    with sr.Microphone() as source:
        print('Hello Pavan, How can I help you today') #Asks for the users command
        r_pause_threshold = 1
        r.ajust_for_ambient_noise(source, duration = 1)
        audio = r.listen(source)

    try:
        command = r.recognize_google(audio) #sets microphone as source (general microphone procedure)
        print('your reply was:' + command +'/n') #tester during excecution (from variable)

    #continual listening for commands

    
    except sr.UnknownValueError: #any noise thatn is unrecogniswed will trigger this command
        assistant(myCommand())

    return command #returns the comand to the AI

#if statementas after excecution:
def assistant(command):
    if 'what\'s up' or 'hi' or 'how is it going' or 'hello' or 'hey kara' in command:
        talkToMe('Everythings going great Pavan')
        #tester (if statement command)
Reply
#2
by any means necessary, for further consultation feel free to email me with the information provided
Reply
#3
the example on https://github.com/pndurette/gTTS shows:
>>> from gtts import gTTS
>>> tts = gTTS('hello')
>>> tts.save('hello.mp3')
I would make sure that works prior to trying to save to mp3.

Then follow instructions for save, or write_to_fp here: https://gtts.readthedocs.io/en/latest/mo...e-gtts.tts
Reply
#4
apologies for the wait however ive tried your solution and its reviewing the exact same syntax. I think its necessary to point out that im a MacOS user, however i was wondering if we could overlook a myriad of solutions to fix this particualr gTTS issue.

perhaps the package is faulty???
Reply
#5
I tried the sample (on Linux) and it works fine.
tried from command line using mpg123 ... works fine
finally tried with system call and it worked as well.

Quote:perhaps the package is faulty???
Above test would indicate that is not the case.

FYI - As a side note, You should use standard library subprocess module to run mpg123 command
import subprocess
from gtts import gTTS

def talkToMe(audio):
    print(audio)
    tts = gTTS(text=audio, lang='en')
    tts.save('audio.mp3')
    subprocess.run(['mpg123',  'audio.mp3'])
tried, and also works fine

perhaps contact the author: http://www.pierre-nick.com
to see if there is a peculiarity with apple
Reply
#6
so after your last response I decided to browse my python files which are imported on my computer, and I cannot identify anything to do with gTTS. funnily enough, my computer terminal states that the gTTS files are a success, however the library files and the syntax errors are proving otherwise. since I am new to gTTS (as I have never used it during the use of IDLE in the past), I was wondering if maybe there are a variety of pip installers, one being the particular choice for your desktop. if this isn't the issue, then I've made plans to take it to the apple store to get this issue fixed, and when it does end up working, ill let you know.

(Btw this may be after the new year)
Reply
#7
Please note that if you have multiple versions of python installed, that they each have their own pip commands
the one that's used can be discovered from shell:
~ $ pip -V
Output:
pip 18.1 from /home/larz60/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pip (python 3.7)
Reply
#8
I have only one version installed and that’s the latest version of IDLE. No worries, as I’ve arranged to see someone in regards to my computer actually being faulty
Reply
#9
Quote:latest version of IDLE
idle, even though it's distributed with python, is a poor excuse for and IDE. It has issues.

Many of the admins and moderators here use VSCode, which is free, and runs on all platforms

You can download version for your OS here: https://code.visualstudio.com/Download

Set up instructions are here: https://python-forum.io/Thread-VS-Code-f...ght=VSCode

I would highly recommend switching, and if not to VSCode, some other IDE, almost anything other than IDLE
google 'Python IDE's' for extensive list.

I've been through many, VSCode wins hands down (my opinion), but an IDE is a personal choice, what you feel comfortable with
Reply
#10
cheers I'm looking into it
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  gtts Nickd12 1 2,249 Oct-24-2020, 02:48 AM
Last Post: ebolisa
  reading text file with gtts Nickd12 0 1,806 Oct-22-2020, 09:37 PM
Last Post: Nickd12

Forum Jump:

User Panel Messages

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