尝试在 Python 中制作 Watson IBM 助手。如何修复我的代码以在没有音频文件的情况下在 IDE Pycharm 中说出答案。使用 VLC
Trying to make a Watson IBM assistant in Python. How can I fix my code to say the answer within the IDE Pycharm without the audio file. Using VLC
这是从另一个基于 Watson 的问题中获取的代码。我正在尝试创建一个系统,在该系统中,我将我的演讲作为问题或命令输入,它说 IDE 中的答案是我上一个问题 My Previous Question 的 link 但我怎么能修复下面的代码。
这是代码...
import vlc
from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator("API Key")
text_to_speech = TextToSpeechV1(
authenticator=authenticator
)
text_to_speech.set_service_url(
'https://api.us-south.text-to-speech.watson.cloud.ibm.com/instances/113cd664-f07b-44fe-a11d-a46cc50caf84')
# define VLC instance
instance = vlc.Instance('--input-repeat=-1', '--fullscreen')
# Define VLC player
player = instance.media_player_new()
# Define VLC media
media = instance.media_new(
text_to_speech.synthesize(
'Hello world',
voice='en-US_AllisonVoice',
accept='audio/wav').get_result().content)
# Set player media
player.set_media(media)
# Play the media
player.play()][1]
登录后,肯定有改进。我更改了密钥和 URL,但只得到 2 个小代码错误...
Traceback (most recent call last):
File "C:/Users/PycharmProjects/IBM Test/iBM tEST.py", line 24, in <module>
accept='audio/wav').get_result().content)
File "C:\Users\PycharmProjects\IBM Test\venv\lib\site-packages\vlc.py", line 1947, in media_new
if ':' in mrl and mrl.index(':') > 1:
TypeError: a bytes-like object is required, not 'str'
错误提示您python 运行时间找不到vlc模块。你需要 运行
pip install python-vlc
或
sudo pip install python-vlc
Edits for secondary question
You are going to need to debug your code to work find out what error the service is returning. To do that you are going to have to break up your code.
try:
result = text_to_speech.synthesize(
'Hello world',
voice='en-US_AllisonVoice',
accept='audio/wav').get_result()
print(result)
except Exception as e:
print(e.message)
edits for third question
没有找到http 404 暗示你写错了url
edits for fourth question
http 403 被禁止,这意味着url、密钥和方法的组合无效。很大程度上表明您正在使用 url 和密钥来获得完全不同的服务。
这是从另一个基于 Watson 的问题中获取的代码。我正在尝试创建一个系统,在该系统中,我将我的演讲作为问题或命令输入,它说 IDE 中的答案是我上一个问题 My Previous Question 的 link 但我怎么能修复下面的代码。
这是代码...
import vlc
from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator("API Key")
text_to_speech = TextToSpeechV1(
authenticator=authenticator
)
text_to_speech.set_service_url(
'https://api.us-south.text-to-speech.watson.cloud.ibm.com/instances/113cd664-f07b-44fe-a11d-a46cc50caf84')
# define VLC instance
instance = vlc.Instance('--input-repeat=-1', '--fullscreen')
# Define VLC player
player = instance.media_player_new()
# Define VLC media
media = instance.media_new(
text_to_speech.synthesize(
'Hello world',
voice='en-US_AllisonVoice',
accept='audio/wav').get_result().content)
# Set player media
player.set_media(media)
# Play the media
player.play()][1]
登录后,肯定有改进。我更改了密钥和 URL,但只得到 2 个小代码错误...
Traceback (most recent call last):
File "C:/Users/PycharmProjects/IBM Test/iBM tEST.py", line 24, in <module>
accept='audio/wav').get_result().content)
File "C:\Users\PycharmProjects\IBM Test\venv\lib\site-packages\vlc.py", line 1947, in media_new
if ':' in mrl and mrl.index(':') > 1:
TypeError: a bytes-like object is required, not 'str'
错误提示您python 运行时间找不到vlc模块。你需要 运行
pip install python-vlc
或
sudo pip install python-vlc
Edits for secondary question
You are going to need to debug your code to work find out what error the service is returning. To do that you are going to have to break up your code.
try:
result = text_to_speech.synthesize(
'Hello world',
voice='en-US_AllisonVoice',
accept='audio/wav').get_result()
print(result)
except Exception as e:
print(e.message)
edits for third question
没有找到http 404 暗示你写错了url
edits for fourth question
http 403 被禁止,这意味着url、密钥和方法的组合无效。很大程度上表明您正在使用 url 和密钥来获得完全不同的服务。