HML
HML

Reputation: 19

IBM Watson SpeechToTextV1 import error

I am trying to use Speech to Text functionality in Watson, I have the following code below:

from __future__ import print_function
import json
from os.path import join, dirname
from watson_developer_cloud import SpeechToTextV1
from watson_developer_cloud.websocket import RecognizeCallback

speech_to_text = SpeechToTextV1(
    username='70d50ee9-c044-4670-a08e-90a84b99580d',
    password='LhielIrnK0VK',
    url='https://stream.watsonplatform.net/speech-to-text/api')

print(json.dumps(speech_to_text.list_models(), indent=2))

print(json.dumps(speech_to_text.get_model('en-US_BroadbandModel'), indent=2))

with open(join(dirname(__file__), '../resources/brian.wav'),
      'rb') as audio_file:
    print(
        json.dumps(
            speech_to_text.recognize(
            audio=audio_file,
            content_type='audio/wav',
            timestamps=True,
            word_confidence=True),
        indent=2))

I already have imported watson_developer_cloud.

https://github.com/watson-developer-cloud/python-sdk/tree/master/watson_developer_cloud

Appreciate any help.

Thanks a lot.

Upvotes: 0

Views: 600

Answers (1)

ShwetaJ
ShwetaJ

Reputation: 519

This is how we do it in typescript. You could translate it into your python code.

import * as watson from "watson-developer-cloud";
let speechToText = new watson.SpeechToTextV1({
            username: <your_service_username>,
            password: <your_service_password>,
            version: <your_service_version>
        });

speechToText.recognize(<your_options_here>, <callback_function_here>);

Upvotes: 1

Related Questions