0

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'
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
Redgar Tech
  • 347
  • 3
  • 13

1 Answers1

1

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.

chughts
  • 4,210
  • 2
  • 14
  • 27
  • but not its dependancies. – chughts May 01 '20 at 16:35
  • I attempted the install and it wouldn't let me. It said pip isn't a recognized command in the PowerShell and command prompt. I tried the python terminal and that didn't work either. – Redgar Tech May 01 '20 at 19:38
  • That is odd as most python distributions come with pip. How did you install the python SDK for ibm-watson ? – chughts May 01 '20 at 21:56
  • I use the IDE Pycharm and it has a repository that I can download SDK's from. IBM-Watson was part of it. – Redgar Tech May 02 '20 at 04:31
  • In addition to this question, I wanted to add speech to text so that I could have my voice as the input and get a different output from the Allison IBM voice with the VLC player saying it live in the IDE. Is this possible? I am still very new to this. – Redgar Tech May 02 '20 at 05:17
  • Can you install `python-vlc` in the same way? If so then your question is really ‘why doesn’t Pycharm correctly install python-vlc’ – chughts May 02 '20 at 08:50
  • I reinstalled and gotten new errors. I replaced my previous errors with these errors. – Redgar Tech May 02 '20 at 23:30
  • I guess you have fixed the python-vlc problem. So now this has become a completely different question. The problem with your code is that it is overoptimistic, in that it is expecting a good response from `get_result()`. It looks like it is getting an error instead, and your code isn't handling it. – chughts May 03 '20 at 11:48
  • How can I fix this issue. Do I get rid of the get_result? This was a program that was said to work on another StackOverflow post that you answered. – Redgar Tech May 03 '20 at 17:06
  • There could be any number of things amiss, wrong credentials, wrong endpoint, firewall problems, proxy problems. To know what you will need to log the output of `get_result` – chughts May 04 '20 at 09:19
  • How can I do that? – Redgar Tech May 04 '20 at 16:20
  • It would be better to use logger, but the basic python method for writing to the console is `print()` – chughts May 05 '20 at 09:55
  • Would it look like this? I put it in my question. – Redgar Tech May 05 '20 at 16:04
  • As you are a python newbie, you might be better of debugging this with `print` for now. I have updated the answer with an example of basic error handling. – chughts May 06 '20 at 08:57
  • I only get one error back now. I have updated the question. – Redgar Tech May 07 '20 at 03:03
  • You are getting a http 404, which means that the url you have specified is wrong. – chughts May 07 '20 at 07:43
  • I changed the URL with the appropriate one and now I get error 403. Like this... Forbidden ERROR:root:Forbidden Traceback (most recent call last): File "C:\Users\PycharmProjects\IBM Test\venv\lib\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: Forbidden, Code: 403 – Redgar Tech May 08 '20 at 03:56
  • HTTP 403 is forbidden, which implies either that the key you are using is not valid for the url you are using, or you are using the url and key of a different service. Please describe how you got both. Also you can show the url so we can check it. Keep the key private, we only want to know how you got it, and for which service you got it. – chughts May 08 '20 at 08:14
  • I got it from the IBM Cloud Website. I have an account I used to get the service. I found that the key was incorrect so I replaced it with the one that matches the URL. I have a small error with the code now. I have updated my question. – Redgar Tech May 08 '20 at 17:12
  • That is a basic python 2 python 3 strings and bytes issues, that has been asked and answered on Stack several times. Please close this question as answered and search stack for the answer to your new question. If you can’t find the answer, then raise a new question that is focused on the fairly basic python issue you are currently seeing. – chughts May 08 '20 at 18:43
  • I really don't know where to look to solve the strings and byte issues. Do you have a couple of StackOverflow posts that I could look at? Also, I don't want to close this question just yet. – Redgar Tech May 08 '20 at 19:30
  • Thank you for all of your help. I am a step closer to achieving my goal. – Redgar Tech May 09 '20 at 19:34
  • I think the question re bad vlc install was answered. Please mark the question as answered. – chughts May 13 '20 at 10:31