Unable to play WAV file generated by IBM Watson's TTS (Text To Speech)
Currently working with the example script found on IBM Watson's GitHub:
- Link: https://github.com/watson-developer-cloud/python-sdk/blob/master/examples/text_to_speech_v1.py
When I run the script, it works perfectly creating the WAV file. However, when I try to play it back within the script, it simply runs and never plays. I tried using PyAudio, Os, Subprocess, and other third party libraries to play the file, however, nothing worked. Is there something I would have to do to the file first before attempting to play it in the script? I'm assuming it has something to do with it being written in binary, which is what the script calls for, but I'm still too new at programming to understand how to solve the problem.
I'll attach my full script below with placeholders for personal info. Thanks!
# coding=utf-8
from os.path import join, dirname
from watson_developer_cloud import TextToSpeechV1
from watson_developer_cloud.websocket import SynthesizeCallback
import subprocess
service = TextToSpeechV1(url='EXAMPLE URL TO API', iam_apikey='EXAMPLE API KEY')
with open(join(dirname(__file__), '..EXAMPLE PATH../resources/output2.wav'),'wb') as audio_file:
response = service.synthesize("What's the weather?", accept='audio/wav', voice="en-US_MichaelVoice").get_result()
audio_file.write(response.content)
def audio_call():
audio_file_path = "..EXAMPLE PATH../resources/output2.wav"
return subprocess.call(["afplay", audio_file_path])
audio_call()
python python-3.x audio subprocess ibm-cloud
|
show 1 more comment
Currently working with the example script found on IBM Watson's GitHub:
- Link: https://github.com/watson-developer-cloud/python-sdk/blob/master/examples/text_to_speech_v1.py
When I run the script, it works perfectly creating the WAV file. However, when I try to play it back within the script, it simply runs and never plays. I tried using PyAudio, Os, Subprocess, and other third party libraries to play the file, however, nothing worked. Is there something I would have to do to the file first before attempting to play it in the script? I'm assuming it has something to do with it being written in binary, which is what the script calls for, but I'm still too new at programming to understand how to solve the problem.
I'll attach my full script below with placeholders for personal info. Thanks!
# coding=utf-8
from os.path import join, dirname
from watson_developer_cloud import TextToSpeechV1
from watson_developer_cloud.websocket import SynthesizeCallback
import subprocess
service = TextToSpeechV1(url='EXAMPLE URL TO API', iam_apikey='EXAMPLE API KEY')
with open(join(dirname(__file__), '..EXAMPLE PATH../resources/output2.wav'),'wb') as audio_file:
response = service.synthesize("What's the weather?", accept='audio/wav', voice="en-US_MichaelVoice").get_result()
audio_file.write(response.content)
def audio_call():
audio_file_path = "..EXAMPLE PATH../resources/output2.wav"
return subprocess.call(["afplay", audio_file_path])
audio_call()
python python-3.x audio subprocess ibm-cloud
Are you sure the.wav
file being produced is playable? Try doing it manually with some other application to verify this.
– martineau
Jan 3 at 1:48
It is, I opened it through iTunes and other apps. Plays there just fine.
– DG.Finance
Jan 3 at 1:51
Does theaudio_file_path
contain space characters? You may have to enclose it in double quote characters. Also, are you getting any kind of error messages?
– martineau
Jan 3 at 2:01
What does runningfile "..EXAMPLE PATH../resources/output2.wav"
says about the file?
– Lie Ryan
Jan 3 at 2:03
@martineau I gave that a shot, still nothing unfortunately.
– DG.Finance
Jan 3 at 2:06
|
show 1 more comment
Currently working with the example script found on IBM Watson's GitHub:
- Link: https://github.com/watson-developer-cloud/python-sdk/blob/master/examples/text_to_speech_v1.py
When I run the script, it works perfectly creating the WAV file. However, when I try to play it back within the script, it simply runs and never plays. I tried using PyAudio, Os, Subprocess, and other third party libraries to play the file, however, nothing worked. Is there something I would have to do to the file first before attempting to play it in the script? I'm assuming it has something to do with it being written in binary, which is what the script calls for, but I'm still too new at programming to understand how to solve the problem.
I'll attach my full script below with placeholders for personal info. Thanks!
# coding=utf-8
from os.path import join, dirname
from watson_developer_cloud import TextToSpeechV1
from watson_developer_cloud.websocket import SynthesizeCallback
import subprocess
service = TextToSpeechV1(url='EXAMPLE URL TO API', iam_apikey='EXAMPLE API KEY')
with open(join(dirname(__file__), '..EXAMPLE PATH../resources/output2.wav'),'wb') as audio_file:
response = service.synthesize("What's the weather?", accept='audio/wav', voice="en-US_MichaelVoice").get_result()
audio_file.write(response.content)
def audio_call():
audio_file_path = "..EXAMPLE PATH../resources/output2.wav"
return subprocess.call(["afplay", audio_file_path])
audio_call()
python python-3.x audio subprocess ibm-cloud
Currently working with the example script found on IBM Watson's GitHub:
- Link: https://github.com/watson-developer-cloud/python-sdk/blob/master/examples/text_to_speech_v1.py
When I run the script, it works perfectly creating the WAV file. However, when I try to play it back within the script, it simply runs and never plays. I tried using PyAudio, Os, Subprocess, and other third party libraries to play the file, however, nothing worked. Is there something I would have to do to the file first before attempting to play it in the script? I'm assuming it has something to do with it being written in binary, which is what the script calls for, but I'm still too new at programming to understand how to solve the problem.
I'll attach my full script below with placeholders for personal info. Thanks!
# coding=utf-8
from os.path import join, dirname
from watson_developer_cloud import TextToSpeechV1
from watson_developer_cloud.websocket import SynthesizeCallback
import subprocess
service = TextToSpeechV1(url='EXAMPLE URL TO API', iam_apikey='EXAMPLE API KEY')
with open(join(dirname(__file__), '..EXAMPLE PATH../resources/output2.wav'),'wb') as audio_file:
response = service.synthesize("What's the weather?", accept='audio/wav', voice="en-US_MichaelVoice").get_result()
audio_file.write(response.content)
def audio_call():
audio_file_path = "..EXAMPLE PATH../resources/output2.wav"
return subprocess.call(["afplay", audio_file_path])
audio_call()
python python-3.x audio subprocess ibm-cloud
python python-3.x audio subprocess ibm-cloud
edited Jan 3 at 2:12
DG.Finance
asked Jan 3 at 1:34
DG.FinanceDG.Finance
237
237
Are you sure the.wav
file being produced is playable? Try doing it manually with some other application to verify this.
– martineau
Jan 3 at 1:48
It is, I opened it through iTunes and other apps. Plays there just fine.
– DG.Finance
Jan 3 at 1:51
Does theaudio_file_path
contain space characters? You may have to enclose it in double quote characters. Also, are you getting any kind of error messages?
– martineau
Jan 3 at 2:01
What does runningfile "..EXAMPLE PATH../resources/output2.wav"
says about the file?
– Lie Ryan
Jan 3 at 2:03
@martineau I gave that a shot, still nothing unfortunately.
– DG.Finance
Jan 3 at 2:06
|
show 1 more comment
Are you sure the.wav
file being produced is playable? Try doing it manually with some other application to verify this.
– martineau
Jan 3 at 1:48
It is, I opened it through iTunes and other apps. Plays there just fine.
– DG.Finance
Jan 3 at 1:51
Does theaudio_file_path
contain space characters? You may have to enclose it in double quote characters. Also, are you getting any kind of error messages?
– martineau
Jan 3 at 2:01
What does runningfile "..EXAMPLE PATH../resources/output2.wav"
says about the file?
– Lie Ryan
Jan 3 at 2:03
@martineau I gave that a shot, still nothing unfortunately.
– DG.Finance
Jan 3 at 2:06
Are you sure the
.wav
file being produced is playable? Try doing it manually with some other application to verify this.– martineau
Jan 3 at 1:48
Are you sure the
.wav
file being produced is playable? Try doing it manually with some other application to verify this.– martineau
Jan 3 at 1:48
It is, I opened it through iTunes and other apps. Plays there just fine.
– DG.Finance
Jan 3 at 1:51
It is, I opened it through iTunes and other apps. Plays there just fine.
– DG.Finance
Jan 3 at 1:51
Does the
audio_file_path
contain space characters? You may have to enclose it in double quote characters. Also, are you getting any kind of error messages?– martineau
Jan 3 at 2:01
Does the
audio_file_path
contain space characters? You may have to enclose it in double quote characters. Also, are you getting any kind of error messages?– martineau
Jan 3 at 2:01
What does running
file "..EXAMPLE PATH../resources/output2.wav"
says about the file?– Lie Ryan
Jan 3 at 2:03
What does running
file "..EXAMPLE PATH../resources/output2.wav"
says about the file?– Lie Ryan
Jan 3 at 2:03
@martineau I gave that a shot, still nothing unfortunately.
– DG.Finance
Jan 3 at 2:06
@martineau I gave that a shot, still nothing unfortunately.
– DG.Finance
Jan 3 at 2:06
|
show 1 more comment
1 Answer
1
active
oldest
votes
[SOLVED]: Apparently there was a problem with my file directory playing WAV files. By changing the file acceptance to "accept = 'audio/wav'" it worked fine.
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%2f54015299%2funable-to-play-wav-file-generated-by-ibm-watsons-tts-text-to-speech%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
[SOLVED]: Apparently there was a problem with my file directory playing WAV files. By changing the file acceptance to "accept = 'audio/wav'" it worked fine.
add a comment |
[SOLVED]: Apparently there was a problem with my file directory playing WAV files. By changing the file acceptance to "accept = 'audio/wav'" it worked fine.
add a comment |
[SOLVED]: Apparently there was a problem with my file directory playing WAV files. By changing the file acceptance to "accept = 'audio/wav'" it worked fine.
[SOLVED]: Apparently there was a problem with my file directory playing WAV files. By changing the file acceptance to "accept = 'audio/wav'" it worked fine.
answered Jan 3 at 19:41
DG.FinanceDG.Finance
237
237
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%2f54015299%2funable-to-play-wav-file-generated-by-ibm-watsons-tts-text-to-speech%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
Are you sure the
.wav
file being produced is playable? Try doing it manually with some other application to verify this.– martineau
Jan 3 at 1:48
It is, I opened it through iTunes and other apps. Plays there just fine.
– DG.Finance
Jan 3 at 1:51
Does the
audio_file_path
contain space characters? You may have to enclose it in double quote characters. Also, are you getting any kind of error messages?– martineau
Jan 3 at 2:01
What does running
file "..EXAMPLE PATH../resources/output2.wav"
says about the file?– Lie Ryan
Jan 3 at 2:03
@martineau I gave that a shot, still nothing unfortunately.
– DG.Finance
Jan 3 at 2:06