How to go around in playing audio files directly in Python 3?
I am trying the gTTS (Google Text To Speach) function in python, saving the mp3 file works (the file is being saved and can be played).
Now I am trying to play the file directly with the below code, but it is throwing an error
Code:
import gtts
import pyglet
import os
import time
text = ("Hello World")
obj = gtts.gTTS(text=text, lang='en')
speech_filename = 'c:/test_voice.mp3'
obj.save(speech_filename)
print("Play sound...")
music = pyglet.media.load(speech_filename, streaming=False)
music.play
sleep.time(music.duration) #prevent from killing
os.remove(speech_filename) #remove temp file
Error:
Traceback (most recent call last):
File "C:pythontext-to-speach.py", line 16, in
music = pyglet.media.load(speech_filename, streaming=False)
File "C:Pythonlibsite-packagespygletmediasourcesloader.py", line 63, in load
source = get_source_loader().load(filename, file)
File "C:Pythonlibsite-packagespygletmediasourcesloader.py", line 84, in load
return WaveSource(filename, file)
File "C:Pythonlibsite-packagespygletmediasourcesriff.py", line 200, in init
'AVbin is required to decode compressed media')
pyglet.media.sources.riff.WAVEFormatException: AVbin is required to decode compressed media
python-3.x
add a comment |
I am trying the gTTS (Google Text To Speach) function in python, saving the mp3 file works (the file is being saved and can be played).
Now I am trying to play the file directly with the below code, but it is throwing an error
Code:
import gtts
import pyglet
import os
import time
text = ("Hello World")
obj = gtts.gTTS(text=text, lang='en')
speech_filename = 'c:/test_voice.mp3'
obj.save(speech_filename)
print("Play sound...")
music = pyglet.media.load(speech_filename, streaming=False)
music.play
sleep.time(music.duration) #prevent from killing
os.remove(speech_filename) #remove temp file
Error:
Traceback (most recent call last):
File "C:pythontext-to-speach.py", line 16, in
music = pyglet.media.load(speech_filename, streaming=False)
File "C:Pythonlibsite-packagespygletmediasourcesloader.py", line 63, in load
source = get_source_loader().load(filename, file)
File "C:Pythonlibsite-packagespygletmediasourcesloader.py", line 84, in load
return WaveSource(filename, file)
File "C:Pythonlibsite-packagespygletmediasourcesriff.py", line 200, in init
'AVbin is required to decode compressed media')
pyglet.media.sources.riff.WAVEFormatException: AVbin is required to decode compressed media
python-3.x
add a comment |
I am trying the gTTS (Google Text To Speach) function in python, saving the mp3 file works (the file is being saved and can be played).
Now I am trying to play the file directly with the below code, but it is throwing an error
Code:
import gtts
import pyglet
import os
import time
text = ("Hello World")
obj = gtts.gTTS(text=text, lang='en')
speech_filename = 'c:/test_voice.mp3'
obj.save(speech_filename)
print("Play sound...")
music = pyglet.media.load(speech_filename, streaming=False)
music.play
sleep.time(music.duration) #prevent from killing
os.remove(speech_filename) #remove temp file
Error:
Traceback (most recent call last):
File "C:pythontext-to-speach.py", line 16, in
music = pyglet.media.load(speech_filename, streaming=False)
File "C:Pythonlibsite-packagespygletmediasourcesloader.py", line 63, in load
source = get_source_loader().load(filename, file)
File "C:Pythonlibsite-packagespygletmediasourcesloader.py", line 84, in load
return WaveSource(filename, file)
File "C:Pythonlibsite-packagespygletmediasourcesriff.py", line 200, in init
'AVbin is required to decode compressed media')
pyglet.media.sources.riff.WAVEFormatException: AVbin is required to decode compressed media
python-3.x
I am trying the gTTS (Google Text To Speach) function in python, saving the mp3 file works (the file is being saved and can be played).
Now I am trying to play the file directly with the below code, but it is throwing an error
Code:
import gtts
import pyglet
import os
import time
text = ("Hello World")
obj = gtts.gTTS(text=text, lang='en')
speech_filename = 'c:/test_voice.mp3'
obj.save(speech_filename)
print("Play sound...")
music = pyglet.media.load(speech_filename, streaming=False)
music.play
sleep.time(music.duration) #prevent from killing
os.remove(speech_filename) #remove temp file
Error:
Traceback (most recent call last):
File "C:pythontext-to-speach.py", line 16, in
music = pyglet.media.load(speech_filename, streaming=False)
File "C:Pythonlibsite-packagespygletmediasourcesloader.py", line 63, in load
source = get_source_loader().load(filename, file)
File "C:Pythonlibsite-packagespygletmediasourcesloader.py", line 84, in load
return WaveSource(filename, file)
File "C:Pythonlibsite-packagespygletmediasourcesriff.py", line 200, in init
'AVbin is required to decode compressed media')
pyglet.media.sources.riff.WAVEFormatException: AVbin is required to decode compressed media
python-3.x
python-3.x
edited Jan 1 at 20:14
user2520212
asked Jan 1 at 13:52
user2520212user2520212
215
215
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
it is looking for AVbin,
check following would help you
https://stackoverflow.com/questions/10302873/python-pyglet-avbin-how-to-install-avbin
I installed AVbin library from [avbin.github.io/AVbin/Download.html] and had to do a simple adjustment to work on Windows 10 64bit - How to fix it on Windows10 [stackoverflow.com/questions/10302873/… But now time is showing an error NameError: name 'sleep' is not defined
– user2520212
Jan 1 at 14:57
1
trytime.sleep()
not suresleep.time()
is exist
– ShivYaragatti
Jan 1 at 15:25
add a comment |
Ok so this is how I solved it, I also added a delay loop that waits for the audio file to finish and delete it afterwards.
import gtts
import pygame
#install pyglet and install http://avbin.github.io/AVbin/Download.html
#extract the avbin.dll from windows/system32/ folder to windows/system/ folder
import os
import time
pygame.mixer.init()
text = ("Hello, World")
obj = gtts.gTTS(text=text, lang='en')
speech_filename = "c:/python/code/test_voice.mp3"
obj.save(speech_filename)
print("Play sound...")
pygame.mixer.music.load(speech_filename)
pygame.mixer.music.play()
busy = True
while busy == True:
if pygame.mixer.music.get_busy() == False:
busy = False
pygame.quit()
os.remove(speech_filename) #remove temp file - remove line to keep file
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996002%2fhow-to-go-around-in-playing-audio-files-directly-in-python-3%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
it is looking for AVbin,
check following would help you
https://stackoverflow.com/questions/10302873/python-pyglet-avbin-how-to-install-avbin
I installed AVbin library from [avbin.github.io/AVbin/Download.html] and had to do a simple adjustment to work on Windows 10 64bit - How to fix it on Windows10 [stackoverflow.com/questions/10302873/… But now time is showing an error NameError: name 'sleep' is not defined
– user2520212
Jan 1 at 14:57
1
trytime.sleep()
not suresleep.time()
is exist
– ShivYaragatti
Jan 1 at 15:25
add a comment |
it is looking for AVbin,
check following would help you
https://stackoverflow.com/questions/10302873/python-pyglet-avbin-how-to-install-avbin
I installed AVbin library from [avbin.github.io/AVbin/Download.html] and had to do a simple adjustment to work on Windows 10 64bit - How to fix it on Windows10 [stackoverflow.com/questions/10302873/… But now time is showing an error NameError: name 'sleep' is not defined
– user2520212
Jan 1 at 14:57
1
trytime.sleep()
not suresleep.time()
is exist
– ShivYaragatti
Jan 1 at 15:25
add a comment |
it is looking for AVbin,
check following would help you
https://stackoverflow.com/questions/10302873/python-pyglet-avbin-how-to-install-avbin
it is looking for AVbin,
check following would help you
https://stackoverflow.com/questions/10302873/python-pyglet-avbin-how-to-install-avbin
answered Jan 1 at 13:57
ShivYaragattiShivYaragatti
32417
32417
I installed AVbin library from [avbin.github.io/AVbin/Download.html] and had to do a simple adjustment to work on Windows 10 64bit - How to fix it on Windows10 [stackoverflow.com/questions/10302873/… But now time is showing an error NameError: name 'sleep' is not defined
– user2520212
Jan 1 at 14:57
1
trytime.sleep()
not suresleep.time()
is exist
– ShivYaragatti
Jan 1 at 15:25
add a comment |
I installed AVbin library from [avbin.github.io/AVbin/Download.html] and had to do a simple adjustment to work on Windows 10 64bit - How to fix it on Windows10 [stackoverflow.com/questions/10302873/… But now time is showing an error NameError: name 'sleep' is not defined
– user2520212
Jan 1 at 14:57
1
trytime.sleep()
not suresleep.time()
is exist
– ShivYaragatti
Jan 1 at 15:25
I installed AVbin library from [avbin.github.io/AVbin/Download.html] and had to do a simple adjustment to work on Windows 10 64bit - How to fix it on Windows10 [stackoverflow.com/questions/10302873/… But now time is showing an error NameError: name 'sleep' is not defined
– user2520212
Jan 1 at 14:57
I installed AVbin library from [avbin.github.io/AVbin/Download.html] and had to do a simple adjustment to work on Windows 10 64bit - How to fix it on Windows10 [stackoverflow.com/questions/10302873/… But now time is showing an error NameError: name 'sleep' is not defined
– user2520212
Jan 1 at 14:57
1
1
try
time.sleep()
not sure sleep.time()
is exist– ShivYaragatti
Jan 1 at 15:25
try
time.sleep()
not sure sleep.time()
is exist– ShivYaragatti
Jan 1 at 15:25
add a comment |
Ok so this is how I solved it, I also added a delay loop that waits for the audio file to finish and delete it afterwards.
import gtts
import pygame
#install pyglet and install http://avbin.github.io/AVbin/Download.html
#extract the avbin.dll from windows/system32/ folder to windows/system/ folder
import os
import time
pygame.mixer.init()
text = ("Hello, World")
obj = gtts.gTTS(text=text, lang='en')
speech_filename = "c:/python/code/test_voice.mp3"
obj.save(speech_filename)
print("Play sound...")
pygame.mixer.music.load(speech_filename)
pygame.mixer.music.play()
busy = True
while busy == True:
if pygame.mixer.music.get_busy() == False:
busy = False
pygame.quit()
os.remove(speech_filename) #remove temp file - remove line to keep file
add a comment |
Ok so this is how I solved it, I also added a delay loop that waits for the audio file to finish and delete it afterwards.
import gtts
import pygame
#install pyglet and install http://avbin.github.io/AVbin/Download.html
#extract the avbin.dll from windows/system32/ folder to windows/system/ folder
import os
import time
pygame.mixer.init()
text = ("Hello, World")
obj = gtts.gTTS(text=text, lang='en')
speech_filename = "c:/python/code/test_voice.mp3"
obj.save(speech_filename)
print("Play sound...")
pygame.mixer.music.load(speech_filename)
pygame.mixer.music.play()
busy = True
while busy == True:
if pygame.mixer.music.get_busy() == False:
busy = False
pygame.quit()
os.remove(speech_filename) #remove temp file - remove line to keep file
add a comment |
Ok so this is how I solved it, I also added a delay loop that waits for the audio file to finish and delete it afterwards.
import gtts
import pygame
#install pyglet and install http://avbin.github.io/AVbin/Download.html
#extract the avbin.dll from windows/system32/ folder to windows/system/ folder
import os
import time
pygame.mixer.init()
text = ("Hello, World")
obj = gtts.gTTS(text=text, lang='en')
speech_filename = "c:/python/code/test_voice.mp3"
obj.save(speech_filename)
print("Play sound...")
pygame.mixer.music.load(speech_filename)
pygame.mixer.music.play()
busy = True
while busy == True:
if pygame.mixer.music.get_busy() == False:
busy = False
pygame.quit()
os.remove(speech_filename) #remove temp file - remove line to keep file
Ok so this is how I solved it, I also added a delay loop that waits for the audio file to finish and delete it afterwards.
import gtts
import pygame
#install pyglet and install http://avbin.github.io/AVbin/Download.html
#extract the avbin.dll from windows/system32/ folder to windows/system/ folder
import os
import time
pygame.mixer.init()
text = ("Hello, World")
obj = gtts.gTTS(text=text, lang='en')
speech_filename = "c:/python/code/test_voice.mp3"
obj.save(speech_filename)
print("Play sound...")
pygame.mixer.music.load(speech_filename)
pygame.mixer.music.play()
busy = True
while busy == True:
if pygame.mixer.music.get_busy() == False:
busy = False
pygame.quit()
os.remove(speech_filename) #remove temp file - remove line to keep file
answered Jan 1 at 20:10
user2520212user2520212
215
215
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996002%2fhow-to-go-around-in-playing-audio-files-directly-in-python-3%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown