0
votes

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.

1
Welcome to Stack Overflow! Stack Overflow is not a discussion forum, it is a Question and Answer site where you can ask a specific programming question that can be answered rather than discussed. Please read How do I ask a good question? and What topics can I ask about here? and then edit your question to conform with the site guidelines. Off-topic questions such as this one are routinely closed, but if edited to ask an answerable question, can be re-opened again. Thanks.NightOwl888

1 Answers

1
votes

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>);