GithubHelp home page GithubHelp logo

pndurette / gtts Goto Github PK

View Code? Open in Web Editor NEW
2.1K 67.0 348.0 529 KB

Python library and CLI tool to interface with Google Translate's text-to-speech API

Home Page: http://gtts.readthedocs.org/

License: MIT License

Python 100.00%
speech python tts text-to-speech gtts speech-api cli python-library pypi

gtts's People

Contributors

ahmadfantastic avatar anselm94 avatar austin-bowen avatar bakaiadam avatar boudewijn26 avatar dependabot[bot] avatar desbma avatar dr-horv avatar evgsd avatar github-actions[bot] avatar gowtham-prudhvi avatar holzhaus avatar hristo-atanasov avatar khursani8 avatar kianmeng avatar kremmydas avatar leo-labs avatar mapreri avatar marctreysonos avatar mashuk999 avatar ns23k avatar ombucha avatar onovy avatar patarapolw avatar pndurette avatar ryan5453 avatar scivision avatar thijstriemstra avatar treymarc avatar wyohknott avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gtts's Issues

Certificate verify failed

Hi, I get the error: (Python 2.7)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)

any fix or workaround? Thank you.

Get audio output directly

Hello,

i have following code:

text = "Hello, my name is Josef."
targetLanguage = 'de'
tts = gTTS(text, targetLanguage)  
tts.save("synthesized.mp3")

Since i play the output directly after this code, is there a way to get the audio output directly as a variable? So i do not have to save and open the mp3 file again.

Thanks!
Josef

SSL Error during Request

Hello,

i am using Python 2.7.6 and gTTS 1.1.3 in a Python virtualenv. Everytime, when i try this command

tts = gTTS(text='Hello', lang='en')

i get back a class 'requests.exceptions.SSLError. I assume it has something to to with version of Python module requests or some other security settings. Can you recommend me which version to use to overcome this issue?

Thanks!
Josef

'NoneType' object has no attribute 'group'

Hello,

I'm getting the error : 'NoneType' object has no attribute 'group' when using the CLI.

I've tried all types of versions of python, re-installed the various modules, etc but nothing works.

typical command would be :
gtts-cli.py -f QGpjRNSVXnyMzGgCwq2XgVtJPDjkcVGAA9jXpBrjxP9r2IxBuv.txt -l 'en' -o test.mp3

Would appreciate help.
C

add the Ukrainian language

Do you have the opportunity to add the Ukrainian language? He is present in the Google translation service. Thank you.

Missing punctuation

Hello,

While looking through this question , I was looking at the punctuation in your code and the chinese language test in your tests. The Chinese comma (",") seems to missing from the punctuation in _tokenize, here. Since Chinese rarely uses periods or spaces, it was entirely possible that he was getting a maximum recursion error by have a space with a combination of 99 characters and commas. I thought I would let you know as I can't imagine the fix requires more than inserting that one character into the list.

Works but very slow

The module is great, I think it sounds very very good. Sadly, when I use it in my application it takes about 9-10 seconds to save the mp3 from about 70 characters string.

Do you have an idea what can be the issue, and is there any possibility for improvement?

Brew formula for gTTS

Should we add a brew formula for gTTS ?
For that , we also need to add an installation script to the repo.

Accents and punctuation not in ascii range

Before installing the gtts 1.1.3, I was getting 403 forbidden errors when using non ASCII characters. After installing this it still doesn't work, but now I get more meaningful errors:

root@VFKJ001:~# gtts-cli -l 'es' -o 'test.mp3' '¿ya estás volviendo a casa?'
'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128)

It happens that both '¿' and 'á', since are not part of ASCII, are not properly parsed. This problem is in any language non ASCII chars, obviously.

Also, and probably unrelated to this, after upgrading to 1.1.3 I get this error when there are only ASCII symbols (although the generation is fine in that case):

root@VFKJ001:~# gtts-cli -l 'es' -o 'test.mp3' 'ya estas volviendo a casa?'
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning

How to append to save mp3 file?

Typical step to generate a speech file (mp3) from text is :

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

if I cannot give all text at once, how can I append to save mp3 file?
For example:
from gtts import gTTS
tts1 = gTTS(text='Hello', lang='en', slow=True)
tts2 = gTTS(text='World', lang='en', slow=True)

How to tts2 append to tts1 to write speech tts1 and tts2 into save file?

Code duplication in parallel projects

Currently google_speech uses the same token generation code as this project. Is it worthwhile to extract the token generation code from this project into a new project and let both projects depend on that? I would be willing to maintain that project.

Cannot run from editor and IPython

I installed gTTS 4 days ago. At first, I used the example and run the script from the editor. It was really nice.
Then after a while, I could not receive anymore results. The script still ran, but no mp3 output from gTTS.
After an investigation, I relieved that now I can only run gTTS from Python console called in Command Prompt, and I have to put each line of scripts into it.
My Python version: 3.5
I'm using Spyder IDE 3.0.1
Windwos 10 64 bit

Problems with char "á"

Many languages use accented vowels. Spanish is one of them. I am using UTF-8 encoding. Apparently the lower case vowel "a" with acute accent "á" (0xC3 0xA1 (c3a1)) is not recognized in the text by your program. The same accented vowel in upper case "Á" (0xC3 0x81 (c381)) works properly. The other accented lower case vowels ("é", "í", "ó", "ú") works fine too. The behaviour in other languages like Italian or French seems just the same than in Spanish (es-es or es-us). Therefore the problem seems limited to the char "á".

Best regards,

Luis

Encoding error (non ascii characters are not valid in gTTS())

Hello I recently found this new amazing project. Cangratulations!!! I found an error while using a file with spanish text in it.

This is the error message:
'ascii' codec can't encode character u'\xbf' in position 0: ordinal not in range(128)
The text in the input file:
¿Cómo sabes que amas a alguien? Filosofía Martha Nussbaum Incomplegencia Teorema de la Verdad del Corazón, de Platón a Proust.

The command:
gtts-cli -o test.mp3 -f test.txt -l 'es'
I am not an expert with codecs and this stuff, I added this lines to gtts-cli.py:

# encoding=utf8
reload(sys)
sys.setdefaultencoding('utf8')

And it worked well, however I don't know if it's the optimal solution.

Noise at the end of mp3 file

Hi,
I am getting a strange noise which sounds like "ps" at the end of the mp3 file, regardless of the string I input. Try following:

gtts-cli "test" -l de -o test.mp3
mpg123 test.mp3 

Can this be fixed? It's really annoying

Soundfiles without sound (or with less sound)

The following consistently results in an mp3-file without sound (0 seconds):

from gtts import gTTS
tts = gTTS(text='你', lang='zh')
tts.save("ni3.mp3")

Sometimes all words result in such empty file, but I assume that happens when the tts service is not available. But even when it works for some words, '你' is one of the counterexamples that never result in a proper mp3-file.
From the around 10 words I used to test, I also noticed that the saved sound from '睡覺' is always a little bit shorter than the actual audio.

Does it still work?

Google asks for a captcha when I go to (translate.google.com/translate_tts?tl=en&q=Test) and gtts-cli produces an empty file. I've tried with different IPs and none of them work. Does gtts-cli still works properly?

Failed to load gTTS module

Hello

I'm using your module for sometime now and I just got an error importing gTTS module after aptitude update on a raspberry (jessie).
The urllib3 package is on version 1.9.1 (installed from apt not pip)
As I can see in your setup.py there is no dependency with urllib3, is it normal or an oversight?
Anyway the problem comes from InsercureRequestWarning that cannot be imported as it is in gTTS code.

Full exception trace:

from gtts import gTTS
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/gtts/init.py", line 2, in
from .tts import gTTS
File "/usr/local/lib/python2.7/dist-packages/gtts/tts.py", line 4, in
from requests.packages.urllib3.exceptions import InsecureRequestWarning
ImportError: cannot import name InsecureRequestWarning

Pip freeze:
alabaster==0.7.10
appdirs==1.4.3
argh==0.26.2
astral==1.4
Babel==2.4.0
backports-abc==0.5
bottle==0.12.7
certifi==2017.4.17
chardet==2.3.0
colorama==0.3.2
decorator==3.4.0
docutils==0.13.1
gevent==1.1.0
greenlet==0.4.12
gTTS==1.2.0
gTTS-token==1.1.1
html5lib==0.999
imagesize==0.7.1
Jinja2==2.9.6
livereload==2.5.1
Mako==1.0.6
Markdown==2.4.1
MarkupSafe==1.0
ndg-httpsclient==0.3.2
numpy==1.8.2
packaging==16.8
passlib==1.6.1
pathtools==0.1.2
pdoc==0.3.2
Pillow==2.6.1
pockets==0.5.1
port-for==0.3.1
psutil==2.1.1
pyasn1==0.1.7
pygame==1.9.2a0
Pygments==2.2.0
pyOpenSSL==0.13.1
pyparsing==2.2.0
python-apt==0.9.3.12
pytz==2017.2
PyYAML==3.12
requests==2.13.0
RPi.GPIO==0.6.3
scipy==0.14.0
simplejson==3.6.5
singledispatch==3.4.0.3
six==1.10.0
snowballstemmer==1.2.1
Sphinx==1.5.6
sphinx-autobuild==0.6.0
sphinx-rtd-theme==0.2.4
sphinxcontrib-napoleon==0.6.1
spidev==3.0
tornado==4.5.1
urllib3==1.21
watchdog==0.8.3
xmljson==0.1.8

A fix:
4 #from requests.packages.urllib3.exceptions import InsecureRequestWarning
5 import requests.packages.urllib3.exceptions as urllib3_exceptions
6 from gtts_token.gtts_token import Token
134 with warnings.catch_warnings():
135 warnings.filterwarnings("ignore", category=urllib3_exceptions.InsecureRequestWarning)
136 r = requests.get(self.GOOGLE_TTS_URL,

Thank you for your module it rocks 😄

requests.exceptions.SSLError > add option to call requests with param verify=False

hi guys,
it is not s big issue, but if you are behind a corp firewall (I am) when trying to call tts.save, there is error with regards to SSL:

tts.save("hello.mp3")
Traceback (most recent call last):
File "", line 1, in
File "C:\Anaconda\lib\site-packages\gtts\tts.py", line 94, in save
self.write_to_fp(f)
File "C:\Anaconda\lib\site-packages\gtts\tts.py", line 114, in write_to_fp
r = requests.get(self.GOOGLE_TTS_URL, params=payload, headers=headers)
File "C:\Anaconda\lib\site-packages\requests\api.py", line 55, in get
return request('get', url, *_kwargs)
File "C:\Anaconda\lib\site-packages\requests\api.py", line 44, in request
return session.request(method=method, url=url, *_kwargs)
File "C:\Anaconda\lib\site-packages\requests\sessions.py", line 456, in request
resp = self.send(prep, *_send_kwargs)
File "C:\Anaconda\lib\site-packages\requests\sessions.py", line 559, in send
r = adapter.send(request, *_kwargs)
File "C:\Anaconda\lib\site-packages\requests\adapters.py", line 382, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError

it is fixed by modifying line 114 from
r = requests.get(self.GOOGLE_TTS_URL, params=payload, headers=headers)
to
r = requests.get(self.GOOGLE_TTS_URL, params=payload, headers=headers,verify=False)

could be helpful to maybe having it as an option configurable when building tts object.

Cheers
Alex

Encoding error : Cannot handle more than 100 non-ascii characters.

when use gTTS, pass in text more than 100 character, it report error:
"'utf8' codec can't decode byte 0xe8 in position 0: unexpected end of data". Test case:
text = "这是一个三岁的小孩
在讲述她从一系列照片里看到的东西。
对这个世界, 她也许还有很多要学的东西,
但在一个重要的任务上, 她已经是专家了:
去理解她所看到的东西。
我们的社会已经在科技上取得了前所未有的进步。"
tts = gTTS(text=text, lang=args.lang)

Feature request - Translate

Not an issue but when I saw the lang argument (text='text here', lang='hi'), I thought it would translate the text to the specified language and return back the output sound in the translated language.

Is there a way we can achieve this? Just like the way it works here - https://translate.google.com

Thanks!

Generated mp3 doens't sound as correct speaking in Russian.

I tried generate russian text longer than 100 symbols and it really doesn't sound as correct speaking. (I know russian language.) I think this happened because the program breaks text on chunks incorrectly.
I also see that

"MAX_CHARS = 100 # Max characters the Google TTS API takes at a time"

not really needed or it has another max value at present time.

ImportError: No module named packages.urllib3.exceptions

karl@karl-ux303ln:~$ gtts-cli "Hello" -l 'en' -o hello.mp3 Traceback (most recent call last): File "/usr/local/bin/gtts-cli.py", line 4, in <module> from gtts import gTTS File "/usr/local/lib/python2.7/dist-packages/gtts/__init__.py", line 2, in <module> from .tts import gTTS File "/usr/local/lib/python2.7/dist-packages/gtts/tts.py", line 4, in <module> from requests.packages.urllib3.exceptions import InsecureRequestWarning ImportError: No module named packages.urllib3.exceptions

Don't really know what this is.

Add support for custom sounds (beep) and other controls like pause and speed

I am building an application where I take documents and convert it to audio. I need a "beep" after every document. I can do it manually by appending mp3 files but it would be nice to include this in the conversion text.
Eg: "[[Speed=0.75]] I like weather today [[beep]] [[pause=1]]. [[Speed=0.5]] Do you like it too?"

gTTs not recognised in venv

I previously installed gTTS in venv and activated the same venv again, and ran my python script and got: "ImportError: No module named gtts". When, I then pip install gtts, I get the errors below. Any ideas why ?

(venv) u:translate_text-to-speech username$ pip install gtts
Collecting gtts
Collecting gtts-token (from gtts)
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from gtts)
Collecting requests (from gtts)
Using cached requests-2.18.4-py2.py3-none-any.whl
Collecting idna<2.7,>=2.5 (from requests->gtts)
Using cached idna-2.6-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests->gtts)
Using cached urllib3-1.22-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests->gtts)
Using cached certifi-2017.7.27.1-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests->gtts)
Using cached chardet-3.0.4-py2.py3-none-any.whl
Installing collected packages: idna, urllib3, certifi, chardet, requests, gtts-token, gtts
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 784, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/init.py", line 83, in ensure_dir
os.makedirs(path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/idna'
(venv) u:translate_text-to-speech username$

I am new to gtts so please help me ,Is there any limit with the number of times i can use the gtts module as after few days of using i got the error of Max retries exceeded with the url and some connection error

The exact error is

(Traceback (most recent call last):
  File "C:\Python\lib\site-packages\requests\packages\urllib3\connection.py", line 135, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "C:\Python\lib\site-packages\requests\packages\urllib3\util\connection.py", line 66, in create_connection
    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
  File "C:\Python\lib\socket.py", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 559, in urlopen
    body=body, headers=headers)
  File "C:\Python\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 345, in _make_request
    self._validate_conn(conn)
  File "C:\Python\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 782, in _validate_conn
    conn.connect()
  File "C:\Python\lib\site-packages\requests\packages\urllib3\connection.py", line 215, in connect
    conn = self._new_conn()
  File "C:\Python\lib\site-packages\requests\packages\urllib3\connection.py", line 144, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x00000132FB57A438>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python\lib\site-packages\requests\adapters.py", line 370, in send
    timeout=timeout
  File "C:\Python\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 609, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Python\lib\site-packages\requests\packages\urllib3\util\retry.py", line 271, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='translate.google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x00000132FB57A438>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    tts.save('Hello.mp3')
  File "C:\Python\lib\site-packages\gtts\tts.py", line 94, in save
    self.write_to_fp(f)
  File "C:\Python\lib\site-packages\gtts\tts.py", line 107, in write_to_fp
    'tk' : self.token.calculate_token(part)}
  File "C:\Python\lib\site-packages\gtts_token\gtts_token.py", line 28, in calculate_token
    seed = self._get_token_key()
  File "C:\Python\lib\site-packages\gtts_token\gtts_token.py", line 58, in _get_token_key
    response = requests.get("https://translate.google.com/")
  File "C:\Python\lib\site-packages\requests\api.py", line 69, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Python\lib\site-packages\requests\api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "C:\Python\lib\site-packages\requests\sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python\lib\site-packages\requests\sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python\lib\site-packages\requests\adapters.py", line 423, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='translate.google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x00000132FB57A438>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)))

Different voices

Not as issue as such but is there any way to use the additional voices that google recently added.
i.e. Male and female voices.
Excellent module by the way, keep up the good work.

Commande-line work, but not the module gTTS

Hi all.

First, Thanks for your job to find the problem of the new API version.

I'm able to use the gtts-cli command line with, for exemple :
gtts-cli.py "Bonjour" -l 'fr' -o hello.mp3 and play it with the command line play, or open it with Itunes.

But when I use the gTTS module, I haven't any problem executing my code, but I can't open the .mp3 (Or other, .flac, ...) with Itunes, And the play command return :

play WARN mp3-util: MAD lost sync play FAIL formats: can't open input file 'hello2.mp3'

Here my code :
from gtts import gTTS tts = gTTS(text='Hello') tts.save("hello2.mp3")

requests.exceptions.HTTPError: 403 Client Error:

This used to work, but started failing all of a sudden.

Traceback (most recent call last):
  File "simple.py", line 29, in <module>
    tts.save(CLIP_NAME)
  File "/usr/lib/python2.7/site-packages/gtts/tts.py", line 94, in save
    self.write_to_fp(f)
  File "/usr/lib/python2.7/site-packages/gtts/tts.py", line 118, in write_to_fp
    r.raise_for_status()
  File "/usr/lib/python2.7/site-packages/requests/models.py", line 840, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://translate.google.com/translate_tts?q=hello&tl=en&client=t&textlen=5&idx=0&total=1&ie=UTF-8&tk=295461.176510

Converting File error

I am trying to convert txt file into mp3 :

gtts-cli.py -f '/home/metal-machine/Desktop/honey.txt' hello.mp3

but it is showing error "Service unavailable":

503 Server Error: Service Unavailable

How with google text-to-speech (gTTS) I can save to the MP3 file 2 Variables with different languages? (Python)

How with google text-to-speech I can save to the MP3 file 2 Variables with different languages? Please help me. Everywhere is written only for 1 language. This is my code:

from gtts import gTTS
import os
import pickle
import pandas as pd

frame = pd.read_csv('file.csv', header=0, sep = '\t', encoding='cp1251')
print(frame)

text1 = list()
text2 = list()

for a, b in zip(frame['English'], frame['Русский']):
    text1.append(a)
    text2.append(b)

print(text1,
      text2)

text1 = str(text1)
text2 = str(text2)

tts1 = gTTS(text=text1, lang='en')
tts2 = gTTS(text=text2, lang='ru')


# tts2.save("from_file.mp3") it work just for one Variable!



with open('from_file.mp3', 'wb') as pickle_file:
    pickle.dump([tts1, tts2], pickle_file) 
# with pickle it doesn't work!

os.system("from_file.mp3")

file content:

English   Русский

tell	  говорить
fly	  летать
sit	  сидеть
act	  действовать

As a solution: I can loop every word with gTTS and add in mp3 file, but how can I add data in mp3 without delete past data ?? I want to create an audio dictionary.

gTTS not wanting to import properly

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

Wrong token with accentuated chars

Hi,

I'm the author of google_speech, a project with slightly different features, but similar goal as gTTS.
Since the recent Google tk change, I am using your token calculation code. I have tried myself to reverse engineer the calculation from JS code, but quickly abandoned, so congrats @Boudewijn26 :)
However if the text contains accentuated chars the token is wrong and consequently Google returns a 403.

To reproduce with gTTS:
gtts-cli 'he' => works fine
gtts-cli 'hé'=> 403 error

The module examples do not work in Windows

The instantiate example and the file like object example do not work in Windows.
I am using Windows 10, 64 bit.
Both give the same error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\gtts\tts.py", line 90, in save
    self.write_to_fp(f)
  File "C:\Python27\lib\site-packages\gtts\tts.py", line 104, in write_to_fp
    r = requests.get(self.GOOGLE_TTS_URL, params=payload)
  File "C:\Python27\lib\site-packages\requests\api.py", line 60, in get
    return request('get', url, **kwargs)
  File "C:\Python27\lib\site-packages\requests\api.py", line 48, in request
    session = sessions.Session()
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 284, in __init
__
    self.headers = default_headers()
  File "C:\Python27\lib\site-packages\requests\utils.py", line 552, in default_h
eaders
    'User-Agent': default_user_agent(),
  File "C:\Python27\lib\site-packages\requests\utils.py", line 521, in default_u
ser_agent
    _implementation = platform.python_implementation()
  File "C:\Python27\Lib\platform.py", line 1456, in python_implementation
    return _sys_version()[0]
  File "C:\Python27\Lib\platform.py", line 1422, in _sys_version
    repr(sys_version))
ValueError: failed to parse CPython sys.version: '2.7.3 |CUSTOM| (default, Aug
8 2013, 05:34:32) [MSC v.1500 32 bit (Intel)]'

gTTS speed

In the documentation it only mentions slow speed, is there a medium or a fast option as well ? Anything related to speed per second which one can set oneself would be super helpful.

gtts-cli.py [-h] (["text to speak"] | -f FILE) [-l LANG] [--slow] [--debug] [-o destination_file]
$ # Read the string 'Hello' in English (slow speed) to hello.mp3
$ gtts-cli "Hello" -l 'en' -o hello.mp3 --slow

Thanks and thanks for this library!

--slow option does not work

Hello,
When I run your example "gtts-cli.py "Hello" -l 'en' -o hello.mp3 -slow" in the terminal in Linuxmint 18.1 xfce, using the latest version through pip, I get the error:
"gtts-cli.py: error: unrecognized arguments: --slow"
Also, I would appreciate it if you could add a parameter to precisely adjust the speed of voice in the command line options (e.g., --speed 0.8)

403 Client Error: Forbidden for url

from gtts import gTTS

tts = gTTS(text="hello", lang='en')
tts.save('F:say.mp3')

Traceback (most recent call last):
File "F:\testaudio.py", line 5, in
tts.save('F:say.mp3')
File "C:\Python27\lib\site-packages\gtts\tts.py", line 90, in save
self.write_to_fp(f)
File "C:\Python27\lib\site-packages\gtts\tts.py", line 108, in write_to_fp
r.raise_for_status()
File "C:\Python27\lib\site-packages\requests\models.py", line 837, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: http://translate.google.com/translate_tts?textlen=5&idx=0&q=hello&tl=en&client=t&total=1&ie=UTF-8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.