-
Notifications
You must be signed in to change notification settings - Fork 3
/
stt.py
41 lines (33 loc) · 972 Bytes
/
stt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Module documentation goes here
and here
and ...
"""
from __future__ import print_function
import json
from os.path import join, dirname
from watson_developer_cloud import SpeechToTextV1
speech_to_text = SpeechToTextV1(
iam_apikey = "your_api_key",
url='url_for_speech_to_text'
)
def getoutput(fname):
"""
Generate English Text from Speech using IBM Watson STT Engine
Parameters
----------
fname: str
the individual file to process on
Returns
-------
text: str
the transcribed text from the audio clip in english
"""
#print("Entered Speech to Text")
with open(join(dirname(__file__), fname),
'rb') as audio_file:
recdata = speech_to_text.recognize(
audio_file, content_type='audio/wav', timestamps=True,
word_confidence=True)
return recdata["results"][0]["alternatives"][0]["transcript"]