0

I would like to retrieve the transcript from the JSON DUMP so that I can put it in a varaible (string) so that I can later use it with the IBM Watson NLU service

My code:

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 return this Json dump:

{
  "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
}

Thank you in advance !

Jeremy.l71
  • 45
  • 7
  • 2
    Weclome to Stackoverflow. As it stands you are very unlikely to get help on this question. It is entirely unclear what you are expecting or what you have tried so far. The code you have posted is also largely irrelevant to your question. In order to get help it is important to give a Minimal and Reproducible code example (https://stackoverflow.com/help/minimal-reproducible-example). For more guidance please see https://stackoverflow.com/help/how-to-ask – Karl Jun 19 '19 at 09:53
  • did you find the solution? – Sarindra Thérèse Nov 11 '21 at 07:05

1 Answers1

0

To Load json file:

with open(file_name) as f:
    d = json.load(f)
Wonka
  • 1,548
  • 1
  • 13
  • 20