Python 2.7: Program does not run

Asked

Viewed 629 times

0

Hello, My program is no longer running, it used to work normally but then just doesn’t work. I checked that the program does not cross the line "Reload(sys)".

# -*- coding: cp1252 -*-
from gtts import gTTS as gtts
import sys
reload(sys);
sys.setdefaultencoding('utf-8');

def audio_br(words, mp3name, language="pt"):
  teste= gtts(text=words,lang=language);
  teste.save("%s.mp3" % mp3name);

audio_br("Segundo ao portal New York times sobre política no Brazil temos","padrão_");
audio_br("Segundo ao portal Catraca Livre sobre tecnologia temos","padrão_a");
audio_br("Segundo ao portal Partiu Intercâmbio sobre bolsas de estudos temos","padrão_b");
audio_br("Segundo ao portal Estudar Fora sobre bolsas de estudos temos","padrão_c");
  • 2

    What do you mean, "It doesn’t rotate"? Answer the questions in the order and answer none: 1 - Is there an error? 2 - Or just open it in the text editor? 3 - Is it linux or Windows? ... I wait 3 answers to be able to help you.

  • And a possible fourth question: what changed from when it worked to when it stopped working? What changed in the code? What changed in the computer? What else have you installed? What have you uninstalled? Changed your computer? Changed the Python version?

    1. The program simply does not run, basically I tested some prints on the screen and only shown the print that comes before Reload. In short nothing appears on the screen and neither generates the mp3 files.
  • 1)The program shows no error, but does not create mp3. I generated some prints on the screen and only those that came before Reload were shown. 2) It opens the shell does not run anything 3) windows 4) I did not install or change anything, I was just testing to see how the mp3 files would be generated. In case if I don’t use this (turn to utf-8) gives some ascii Encode error

  • And what is the function of reload in that code?

  • basically not to give error of encounter when I go to do the audio . mp3 using gtts

    1. How are you running this issue, double click or by terminal? Try to run on terminal and catch the error.
  • @Andersoncarloswoss I believe that this is the function of reload in his script: https://stackoverflow.com/a/17628350/1518921

Show 3 more comments

1 answer

2


I have exactly Python 2.7 installed on my machine, the dots and comma did not affect the functioning, the only mistake I ever made was:

No module named gtts

This is because I didn’t have the module installed, so I installed it via pip cmd (I am using Windows):

pip install gTTS

the result was:

resultado

See possible errors

Files are being saved in another folder

Your script if executed for example:

 c:\Users\user> python c:\exemplos\python\script.py

Will save the .mp3 in the briefcase c:\Users\user and not in the folder c:\exemplos\python

Or so (Unix-like):

 eu@debian:~$ python /home/usuario/exemplos/python/script.py

Will save the .mp3 in the briefcase /home/[usuario] (~$ indicates the home user) and not in the folder /home/usuario/exemplos/python

So he saves from where he executed.

Lack of written permission

Maybe the location where you are trying to save the files does not have write permission, it depends a lot on where you are trying to run and the operating system, whether your .py for example in the folder c:\Programs and Files will not record the .mp3 unless it has administrative mode, of course if you are trying to run from that folder.

Coding

If your .py is saved with a different encoding than utf-8 may cause this error:

Traceback (most recent call last):
  File "tests/n.py", line 12, in <module>
    audio_br("Segundo ao portal New York times sobre polÝtica no Brazil temos","
padrÒo_");
  File "tests/n.py", line 9, in audio_br
    teste= gtts(text=words,lang=language);
  File "C:\Python27\lib\site-packages\gtts\tts.py", l
ine 94, in __init__
    if self._len(text) <= self.MAX_CHARS:
  File "C:\Python27\lib\site-packages\gtts\tts.py", l
ine 154, in _len
    return len(text.decode('utf8'))
  File "C:\Python27\lib\encodings\utf_8.py", line 16,
 in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xed in position 42: invalid
continuation byte

This is because the lib apparently works with utf-8.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.