Show Menu
Cheatography

IBM Watson Cheat Sheet (DRAFT) by

abcdefghijklmnopqrstuvwxyz

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Setup

Download Python
Install PIP
curl https:­//b­oot­str­ap.p­yp­a.i­o/g­et-­pip.py -o get-pip.py | python3 get-pip.py
Install Packages
pip3 install opencv­-python ibm-watson

Basic setup

#Imports
from ibm_watson import VisualRecognitionV3
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
 
#Build connection to the Service
authenticator = IAMAuthenticator('API_KEY')
service = VisualRecognitionV3(
    version='2020-02-26',
    authenticator=authenticator
)
#Connect
service.set_service_url('YOUR_URL')
 

Text to Speech

#Import required packages
from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

#connect to service
authenticator = IAMAuthenticator('{apikey}')
text_to_speech = TextToSpeechV1(
    authenticator=authenticator
)

text_to_speech.set_service_url('{url}')

#write the response from the server to the hello_world.wav audio file

#open the audio file
with open('hello_world.wav', 'wb') as audio_file:
    #write something into the file
    audio_file.write(
        #get the response from the service and set the parameters as you like
        text_to_speech.synthesize(
            'Hello world',
            voice='en-US_AllisonVoice',
            accept='audio/wav'        
        ).get_result().content)