IBM Watson在Python中的文本到语音。没有这样的子资源

问题描述 投票:0回答:1

我试图根据一个简单的文本生成一个音频文件。

from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('O6...............N')
text_to_speech = TextToSpeechV1(authenticator=authenticator)

text_to_speech.set_service_url('https://api.eu-gb.text-to-speech.watson.cloud.ibm.com/instances/b95d7....................956/v1/synthesize')

但是,我得到了以下的输出。

ERROR:root: No such child resource.
Traceback (most recent call last):
  File "/Applications/anaconda2/envs/py3/lib/python3.6/site-packages/ibm_cloud_sdk_core/base_service.py", line 229, in send
    response.status_code, error_message, http_response=response)
ibm_cloud_sdk_core.api_exception.ApiException: Error: No such child resource., Code: 404 , X-global-transaction-id: 834e9.................698f5

我做错了什么?

python text-to-speech ibm-watson
1个回答
0
投票

对于 set_service_url,使用基本网址 https://api.eu-gb.text-to-speech.watson.cloud.ibm.com如图所示 API参考.

然后,你可以调用 synthesize 方法(见 例子 在API参考中)。)

with open('hello_world.wav', 'wb') as audio_file:
    audio_file.write(
        text_to_speech.synthesize(
            'Hello world',
            voice='en-US_AllisonVoice',
            accept='audio/wav'        
        ).get_result().content)
© www.soinside.com 2019 - 2024. All rights reserved.