This is the code grabbed from another Watson based question. I am trying to make a system where I input my speech as a question or command and it says an answer within the IDE here is the link to my previous question My Previous Question but how can I fix the code below.
This is the code...
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]
After Logging, there was definitely an improvement. I changed the key and URL and only get 2 small code errors...
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'
The error is telling you that the python runtime can't find the vlc module. You need to run
pip install python-vlc
or
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 is not found implying that you have the wrong url
edits for fourth question
http 403 is forbidden, which implies the combination of url, key and method is invalid. Largely suggesting that you are using the url and key for a completely different service.