-5

The output of the code below should be a voice saying, 'Welcome to geeks for geeks!', but I'm getting 1, why?

from gtts import gTTS 
import os  
mytext = 'Welcome to geeksforgeeks!'
language = 'en'
myobj = gTTS(text=mytext, lang=language, slow=False) 
myobj.save("welcome.mp3")  
os.system("mpg321 welcome.mp3")
desertnaut
  • 57,590
  • 26
  • 140
  • 166

2 Answers2

0

This code is perfect and should work provided you have installed gtts into your pip environment and mpg321 is on your path. I tested this code on Mac OS (where I did brew install mpg321 and on Ubuntu 18.04 (sudo apt install mpg321). In both cases, I heard a voice saying "welcome to geeks for geeks".

If you want more help with this, you will have to provide more details about the context in which this code is being run. Here are some commands you should post the output of, to give more info people like me who want to help you. :)

python --version

pip freeze

uname -a

Also, have you tried playing a different mp3 file with mpg321? It might be that mpg321 is not working properly.

Peaceful James
  • 1,807
  • 1
  • 7
  • 16
0

I was able to create the audio file and play it with your code. I first had to sudo apt install mpg321 and pip install gTTS .

I have published a Repl.it with the code working at: https://replit.com/@redten/StackOverflow-Q-62257928?v=1

agentred5
  • 61
  • 8
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. – rachwa Jul 31 '22 at 12:23