Skip to content

Instantly share code, notes, and snippets.

@santiagobasulto
Created March 17, 2017 20:40
Show Gist options
  • Save santiagobasulto/bc0e4c2c29ae8086e775a4d666fdbd60 to your computer and use it in GitHub Desktop.
Save santiagobasulto/bc0e4c2c29ae8086e775a4d666fdbd60 to your computer and use it in GitHub Desktop.
"""Sample code to use the IBM Watson Speech to Text API.
See more at https://blog.rmotr.com.
"""
import json
from watson_developer_cloud import SpeechToTextV1
IBM_USERNAME = "<YOUR-USERNAME>"
IBM_PASSWORD = "<YOUR-PASSWORD>"
stt = SpeechToTextV1(username=IBM_USERNAME, password=IBM_PASSWORD)
audio_file = open("audio_file.flac", "rb")
with open('transcript_result.json', 'w') as fp:
result = stt.recognize(audio_file, content_type="audio/x-flac",
continuous=True, timestamps=False,
max_alternatives=1)
json.dump(result, fp, indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment