Coder Social home page Coder Social logo

Comments (14)

apaparazzi0329 avatar apaparazzi0329 commented on July 17, 2024

Hi, @GuyKh. Can you tell me where you found this example?

from python-sdk.

GuyKh avatar GuyKh commented on July 17, 2024

@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.

GuyKh avatar GuyKh commented on July 17, 2024

Any news on that @apaparazzi0329?

from python-sdk.

apaparazzi0329 avatar apaparazzi0329 commented on July 17, 2024

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.

apaparazzi0329 avatar apaparazzi0329 commented on July 17, 2024

Are you still getting this same error on your side?

from python-sdk.

GuyKh avatar GuyKh commented on July 17, 2024

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.

apaparazzi0329 avatar apaparazzi0329 commented on July 17, 2024

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.

GuyKh avatar GuyKh commented on July 17, 2024

@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.

apaparazzi0329 avatar apaparazzi0329 commented on July 17, 2024

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.

apaparazzi0329 avatar apaparazzi0329 commented on July 17, 2024

This will allow me to see if the python sdk is at fault or the TTS service itself

from python-sdk.

GuyKh avatar GuyKh commented on July 17, 2024

@apaparazzi0329

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.

GuyKh avatar GuyKh commented on July 17, 2024

@apaparazzi0329

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.

jeff-arn avatar jeff-arn commented on July 17, 2024

@GuyKh the Watson APIs don't support HTTP, and HTTPS is required in order to authenticate.

from python-sdk.

GuyKh avatar GuyKh commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.