我如何在Python中接收Watson Speech to Text SDK的全部输出?

问题描述 投票:3回答:1

经过大量测试,我能够从我在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
}

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

python speech-recognition ibm-watson
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.