Warm tip: This article is reproduced from stackoverflow.com, please click
ibm-watson python speech-recognition

How do I receive the entire output of the Watson Speech to Text SDK in Python?

发布于 2020-04-07 10:08:41

after a lot of testing, I was able to receive an output from the application i created in python to convert speech to text using IBM bluemix. code:

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('xxxx')
service = SpeechToTextV1(authenticator=authenticator)
service.set_service_url('https://api.us-east.speech-to-text.watson.cloud.ibm.com')

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(join(dirname('__file__'), 'testvoice3.wav'),
          'rb') as audio_file:
    print(json.dumps(
        service.recognize(
            audio=audio_file,
            content_type='audio/wav',
            timestamps=True,
            word_confidence=True,model='en-US_NarrowbandModel',
        continuous=True).get_result(),
        indent=2))

I am receiving an output which looks like the below:

            [
              "no",
            [
              "their",
              0.41
            ],
            [
              "lives",
              0.1
            ],
            [
              "you",
              0.56
            ],
            [
              "take",
              1.0
            ],
            [
              "Kerr",
              0.95
            ],
            [
              "bye",
              0.4
            ],
            [
              "bye",
              0.99
            ]
          ]
        }
      ],
      "final": true
    }
  ],
  "result_index": 0
}

I just want to to receive the entire output in one place instead of this such format. I just want the transcript seperately from the confidence scores. So i can export this to a text file. How would i go about this?

Questioner
hartville zillow
Viewed
28
chughts 2020-01-31 19:29

That output is word confidence. There should be an entry in the output with the full text, most likely higher up in your listing.

To condense the output to only the transcript take out the options word_confidence=True and timestamps=True.