Skip to content

Instantly share code, notes, and snippets.

@stevemar
Last active December 2, 2020 15:12
Show Gist options
  • Save stevemar/55ac4c644337294cb88b76c848418f25 to your computer and use it in GitHub Desktop.
Save stevemar/55ac4c644337294cb88b76c848418f25 to your computer and use it in GitHub Desktop.
example python and output for using watson STT
import json
from os.path import join, dirname
from ibm_watson import SpeechToTextV1
from ibm_watson.websocket import RecognizeCallback, AudioSource
import threading
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('dnaxxxxxxYN4')
service = SpeechToTextV1(authenticator=authenticator)
service.set_service_url('https://stream.watsonplatform.net/speech-to-text/api')
#models = service.list_models().get_result()
#print(json.dumps(models, indent=2))
model = service.get_model('en-US_BroadbandModel').get_result()
print(json.dumps(model, indent=2))
with open('hello_world.wav', 'rb') as audio_file:
print(json.dumps(
service.recognize(
audio=audio_file,
content_type='audio/wav',
timestamps=True,
word_confidence=True).get_result(),
indent=2))
{
"name": "en-US_BroadbandModel",
"rate": 16000,
"language": "en-US",
"description": "US English broadband model.",
"supported_features": {
"custom_language_model": true,
"speaker_labels": true
},
"url": "https://api.us-south.speech-to-text.watson.cloud.ibm.com/instances/7cb61ab5-ac76-430d-bcce-8adba47d0f7f/v1/models/en-US_BroadbandModel"
}
{
"result_index": 0,
"results": [
{
"final": true,
"alternatives": [
{
"transcript": "how can I T. is the greatest hackathon event ever ",
"confidence": 0.62,
"timestamps": [
[
"how",
0.0,
0.22
],
[
"can",
0.22,
0.52
],
[
"I",
0.52,
0.65
],
[
"T.",
0.65,
0.91
],
[
"is",
0.91,
1.06
],
[
"the",
1.06,
1.16
],
[
"greatest",
1.16,
1.63
],
[
"hackathon",
1.63,
2.01
],
[
"event",
2.01,
2.47
],
[
"ever",
2.51,
2.96
]
],
"word_confidence": [
[
"how",
0.06
],
[
"can",
0.08
],
[
"I",
0.68
],
[
"T.",
0.56
],
[
"is",
0.65
],
[
"the",
1.0
],
[
"greatest",
0.94
],
[
"hackathon",
0.03
],
[
"event",
0.93
],
[
"ever",
0.98
]
]
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment