I am writing a program which reads a string, then convert it into speech and play it as mp3. But the program does not play the music. I have checked and find out that the mp3 file is created and can be played with standard mp3 players but not the script. I am using gtts module (for converting text to speech) and vlc module (to play mp3) The code is like this.Please note that 'm' is the text I want to convert to sound.
tts = gTTS(text=m, lang='en')
tts.save("greeting.mp3")
p = vlc.MediaPlayer("greeting.mp3")
p.play()
I have further found out that the mp3 plays when I provide an infinite loop after play command.Like this
tts = gTTS(text=m, lang='en')
tts.save("greeting.mp3")
p = vlc.MediaPlayer("greeting.mp3")
p.play()
while True:
pass
Is there any way I can avoid that Infinite loop.I have already imported all the required modules to the project.