Я хотел бы получить стенограмму из JSON DUMP, чтобы я мог поместить ее в переменную (строку), чтобы впоследствии я мог использовать ее со службой IBM Watson NLU
Мой код:
class MyRecognizeCallback(RecognizeCallback):
def __init__(self):
RecognizeCallback.__init__(self
def on_transcription(self, transcript):
print(transcript)
def on_connected(self):
print('Connection was successful')
def on_error(self, error):
print('Error received: {}'.format(error))
def on_inactivity_timeout(self, error):
print('Inactivity timeout: {}'.format(error))
def on_listening(self):
print('Service is listening')
def on_hypothesis(self, hypothesis):
print(hypothesis)
def on_data(self, data):
print(json.dumps(data, indent=2))
def on_close(self):
print("Connection closed")
myRecognizeCallback = MyRecognizeCallback()
with open(join(dirname(__file__), './.', 'output.wav'),
'rb') as audio_file:
audio_source = AudioSource(audio_file)
speech_to_text.recognize_using_websocket(
audio=audio_source,
content_type='audio/wav',
recognize_callback=myRecognizeCallback,
model='fr-FR_BroadbandModel')
API WATSON возвращает этот дамп Json:
{
"results": [
{
"alternatives": [
{
"confidence": 0.87
"transcript": "several tornadoes touch down as a line of
severe thunderstorms swept through colorado on sunday "
}
],
"final": true
}
],
"result_index": 0
}
Заранее спасибо!