温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - How do I receive the entire output of the Watson Speech to Text SDK in Python?
ibm-watson python speech-recognition

其他 - 如何使用Python接收Watson Speech to Text SDK的全部输出?

发布于 2020-04-07 10:09:55

经过大量测试,我能够从我在python中创建的应用程序接收输出,以使用IBM bluemix将语音转换为文本。码:

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))

我收到的输出如下所示:

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

我只想在一个地方接收整个输出,而不是这种格式。我只想把成绩单和信心分数分开。所以我可以将其导出到文本文件。我将如何处理?

查看更多

提问者
hartville zillow
被浏览
24
chughts 2020-01-31 19:29

该输出是词的置信度。输出中应该有一个带有全文的条目,最有可能在您列表的上方。

要将输出压缩为仅成绩单,请取出选项word_confidence=Truetimestamps=True