Comments (14)
Hi, @GuyKh. Can you tell me where you found this example?
from python-sdk.
@apaparazzi0329
From the API docs: https://cloud.ibm.com/apidocs/text-to-speech?code=python#synthesize
Copying the full example:
from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('{apikey}')
text_to_speech = TextToSpeechV1(
authenticator=authenticator
)
text_to_speech.set_service_url('{url}')
with open('hello_world.wav', 'wb') as audio_file:
audio_file.write(
text_to_speech.synthesize(
'Hello world',
voice='en-US_AllisonV3Voice',
accept='audio/wav'
).get_result().content)
from python-sdk.
Any news on that @apaparazzi0329?
from python-sdk.
Hi @GuyKh, thanks for reminding me about this. Unfortunately, I wasn't able to replicate your issue. I copied the exact code from the example and it worked without any edits using the same version of the python-sdk as you are. I tested on Python 3.8.7 and 3.9.2 with the same successful results.
from python-sdk.
Are you still getting this same error on your side?
from python-sdk.
Hey @apaparazzi0329 - just reproduced this on a new pc:
Again - reproducing the code:
print("Saying: " + message)
authenticator = IAMAuthenticator("<MyAPIKey>")
service = TextToSpeechV1(authenticator)
service.set_service_url("http://api.eu-de.text-to-speech.watson.cloud.ibm.com")
default_voice = "en-US_KevinV3Voice"
output_format = "audio/mp3"
service.set_default_headers({"x-watson-learning-opt-out": "true"})
print ('about to write the file')
with open('temp.mp3', 'wb') as audio_file:
audio_file.write(
service.synthesize(
message, accept=output_format, voice=default_voice
).get_result().content)
Error is:
Saying: Hello Mate
about to write the file
Traceback (most recent call last):
File "watson.py", line 25, in <module>
main(sys.argv[1:])
File "watson.py", line 20, in main
service.synthesize(
File "C:\Python38\lib\site-packages\ibm_watson\text_to_speech_v1.py", line 343, in synthesize
response = self.send(request, **kwargs)
File "C:\Python38\lib\site-packages\ibm_cloud_sdk_core\base_service.py", line 319, in send
raise ApiException(response.status_code, http_response=response)
ibm_cloud_sdk_core.api_exception.ApiException: Error: Required parameter 'text' is missing., Code: 400 , X-global-transaction-id: efd96b9a-3132-47e9-9158-6ef0277341b5
from python-sdk.
Hmm for some reason the text parameter is not being passed through even though you are defining it correctly in the synthesize
method. Try replacing message
with text=message
in your synthesize call
from python-sdk.
@apaparazzi0329
Tried that too:
...
with open('temp.mp3', 'wb') as audio_file:
audio_file.write(
service.synthesize(
text=message, accept=output_format, voice=default_voice
).get_result().content)
and still getting :
File "watson.py", line 20, in main
service.synthesize(
File "C:\Python38\lib\site-packages\ibm_watson\text_to_speech_v1.py", line 343, in synthesize
response = self.send(request, **kwargs)
File "C:\Python38\lib\site-packages\ibm_cloud_sdk_core\base_service.py", line 319, in send
raise ApiException(response.status_code, http_response=response)
ibm_cloud_sdk_core.api_exception.ApiException: Error: Required parameter 'text' is missing., Code: 400 , X-global-transaction-id: cf20db7c-5ee6-4144-895f-5df8caf23633
from python-sdk.
Ok, can I ask you to do some debugging for me since I cannot recreate this issue. Can you set your service_url to http://localhost:9000
and then open up a terminal and run nc -l 9000
; after those steps run your code again. This will allow you to see the request that is being sent by the Watson python-sdk in your terminal. Send that data from your terminal here being sure to black out any api keys that may be revealed
from python-sdk.
This will allow me to see if the python sdk is at fault or the TTS service itself
from python-sdk.
POST /v1/synthesize?voice=en-US_KevinV3Voice HTTP/1.1
Host: localhost:9000
User-Agent: watson-apis-python-sdk-5.3.0 Windows 10 3.8.2
Accept-Encoding: gzip, deflate
Accept: audio/mp3
Connection: keep-alive
X-IBMCloud-SDK-Analytics: service_name=text_to_speech;service_version=V1;operation_id=synthesize
content-type: application/json
x-watson-learning-opt-out: true
Authorization: Bearer eyJraWQiOiIyMDIxMDgxOTA4MTciLCJhbGciOiJSUzI1NiJ9.eyJpYW1faWQiOiJpYW0tU2VydmljZUlkLTFhYzAxODc0LTVjMzMtNDdmYy1hM........
Content-Length: 20
{"text": "Hey Mate"}
from python-sdk.
I actually think I've found the issue.
I've noticed that i've been using server http://api.eu-de.text-to-speech.watson.cloud.ibm.com
Note -HTTP and not HTTPS.
Changing it to HTTPS solves this.
@apaparazzi0329 - can you try to reproduce that with HTTP?
Maybe it means that something in your API uses a different version for HTTP and HTTPS.
from python-sdk.
@GuyKh the Watson APIs don't support HTTP, and HTTPS is required in order to authenticate.
from python-sdk.
I'd argue that the endpoint should have a better, more informative, response than "text" field is missing.
But anyway. Thanks for the comment
from python-sdk.
Related Issues (20)
- Can not import MetadataOptions for use in Features request HOT 2
- Custom machine learning model HOT 4
- Have an idea HOT 2
- AssistantV2 API - time incorrectly resolved when timezone is provided HOT 4
- Inconsistent Behavior in the Delete_Document Method of the SDK HOT 6
- Minor: Link to docs from README does not work HOT 1
- CloudPakForDataAuthenticator not working with CPD 3.5.3 HOT 3
- Service fails behind proxy HOT 1
- speech to text HOT 1
- Watson stt examples print out bunch of hex data HOT 10
- Pinned down websocket-client==1.1.0 HOT 6
- RecognizeListener outputs websocket trace information HOT 1
- Intermittent problem when using http sync transcription API HOT 2
- Parameter `character_insertion_bias` not implemented HOT 1
- Python Watson NLU APIs: No way to access coreference data
- Handshake status 403 Forbidden
- Fail to import 'ClassificationOptions' from 'ibm_watson.natural_language_understanding_v1' in py3.7
- AttributeError: 'DiscoveryV2' object has no attribute 'list_documents' HOT 1
- watson assistant rest API returns an empty results HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-sdk.