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

gTTS not wanting to import properly #50

Closed
philipposslicher opened this issue Nov 8, 2016 · 23 comments
Closed

gTTS not wanting to import properly #50

philipposslicher opened this issue Nov 8, 2016 · 23 comments

Comments

@philipposslicher
Copy link

philipposslicher commented Nov 8, 2016

So I am trying to get gTTS to work
I know that you are supposed to import with from gtts import gTTS.
I have a new virtualenv, with gtts, and speechrecognition installed and no matter what I do I can't get gTTS to import
If I try: from gtts import gTTS
ImportError: cannot import name 'gTTS'
Any ideas?
Using Python 3.5.2

@jhoelzl
Copy link

jhoelzl commented Nov 8, 2016

How have you installed the module?

Verify with pip list if gTTS is installed in your environment.

When you have activated your virtual environment, run

pip install gTTS without sudo, otherwise it will be installed in your main python folder of your operating system.

@philipposslicher
Copy link
Author

philipposslicher commented Nov 8, 2016

I installed it with pip install gTTS. I have checked its installed in the virtualenv, running import gtts (I ran this just to test if its installed) shows thats its installed.
Output of pip list

gTTS (1.1.6)
gTTS-token (1.1.1)
pip (9.0.1)
PyAudio (0.2.9)
requests (2.11.1)
setuptools (28.8.0)
SpeechRecognition (3.4.6)
wheel (0.30.0a0)

@jhoelzl
Copy link

jhoelzl commented Nov 8, 2016

and in your environment, the module files exist under lib/python3.5/site-packages/gtts ?

@philipposslicher
Copy link
Author

philipposslicher commented Nov 8, 2016

Yep, both gtts, gtts_token, gTTS_token-1.1.1.dist-info, and gTTS-1.1.6.dist-info

@jhoelzl
Copy link

jhoelzl commented Nov 9, 2016

Could you try the command from gtts import gTTS using python -i in your environment?

@philipposslicher
Copy link
Author

It gives me this:
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name 'gTTS'

@jhoelzl
Copy link

jhoelzl commented Nov 9, 2016

You could try this instead:

import gtts

tts = gtts.gTTS(text='Hello', lang='en')
tts.save("hello.mp3")

@philipposslicher
Copy link
Author

That gives this though:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'gtts' has no attribute 'gTTS'

@jhoelzl
Copy link

jhoelzl commented Nov 9, 2016

Maybe this is related to http://stackoverflow.com/questions/16981921/relative-imports-in-python-3.
What is the name of your script file? It should no be gtts.py.

Maybe try something like this:

import gtts

tts = gtts.tts.gTTS(text='Hello', lang='en')
tts.save("hello.mp3")

or remove the dots in the import command in __init__.py

@philipposslicher
Copy link
Author

Ok so it I didn't know that the script shouldnt be named after the module. I have fixed it and now it seems to run. Now I'm wondering, is it possible for gTTS to speak the text without needing to write to a file, then playing it back?

@jhoelzl
Copy link

jhoelzl commented Nov 9, 2016

Currently not, i also requested this feature in #26

@philipposslicher
Copy link
Author

What would be recommended for playing a file, and also deleting (cause it would be temp)

@jhoelzl
Copy link

jhoelzl commented Nov 10, 2016

You can do this to play the file and then remove it:

from gtts import gTTS
import os

filename = "temp"
tts = gTTS(text='Hello', lang='en')
tts.save(filename + ".mp3")

# Convert MP3 to Wav and Play
os.system('avconv -i ' + filename + '.mp3 -ac 1 -ar 44100 '  + filename + '.wav' )
os.system('aplay ' + filename+'.wav')

os.remove(filename+'.wav')
os.remove(filename+'.mp3')

@ghost
Copy link

ghost commented Jan 2, 2018

@philipposslicher
I am also having the same problem with gtts module how did you corrected can you pls explain it.
AttributeError: module 'gtts_1' has no attribute 'gTTs'

@JaiSh12345
Copy link

I wrote >>import gtts
I am getting:
Traceback (most recent call last): File "<pyshell#10>", line 1, in <module> import gtts File "C:\Python34\lib\gtts\__init__.py", line 3, in <module> from .tts import gTTS, gTTSError File "C:\Python34\lib\gtts\tts.py", line 6, in <module> from gtts_token import gtts_token ImportError: No module named 'gtts_token'
What to do?

@JaiSh12345
Copy link

Then I tried:
>>> from gtts import gTTS
>>> gTTS('Hello')
Output? This:
Traceback (most recent call last): File "<pyshell#14>", line 1, in <module> gTTS('Hello') File "C:\Python34\lib\gtts\tts.py", line 140, in __init__ self.token = gtts_token.Token() NameError: name 'gtts_token' is not defined

@seriadiallo
Copy link

hello rerun this command first

pip install gTTS
it seems that this command crashed ,
then retry

@redixhumayun
Copy link

Hi, this seems to still be an issue.

I am using
-macOS Mojave 10.14.3
-Python 3.7
-gTTs 2.0.3
-gTTs-token 1.1.3

@RohitKumar2511
Copy link

Traceback (most recent call last):
File "C:/python/assistant.py", line 1, in
from gtts import gTTS
ModuleNotFoundError: No module named 'gtts'

Please help with this. It says module not found I checked Its was there, but still got this error...

@ajayprajapat171
Copy link

Traceback (most recent call last):
File "C:/python/assistant.py", line 1, in
from gtts import gTTS
ModuleNotFoundError: No module named 'gtts'

Please help with this. its same problem coming in my side if you have any solution please help me

@RohitKumar2511
Copy link

Brother, @ajayprajapat171, when I can't find out what's the error is... I just unistalled and reinstalled... finally error got solved

@AhmudulHassan
Copy link

Brother, @ajayprajapat171, when I can't find out what's the error is... I just unistalled and reinstalled... finally error got solved

Thanks brother.. i tried this way and finally fixed out..

@AndresVilla123
Copy link

Is true, I unistalled and reinstalled.
Now it works.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants