如何在 Python 中接收 Watson Speech to Text SDK 的全部输出?
How do I receive the entire output of the Watson Speech to Text SDK in Python?
经过大量测试后,我能够从我在 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
}
我只想在一个地方接收整个输出,而不是这种格式。我只想将成绩单与置信度分数分开。所以我可以将其导出到文本文件。我该怎么做?
该输出是单词置信度。输出中应该有一个包含全文的条目,很可能在您的列表中较高的位置。
要将输出压缩为仅转录本,请删除选项 word_confidence=True
和 timestamps=True
。
经过大量测试后,我能够从我在 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
}
我只想在一个地方接收整个输出,而不是这种格式。我只想将成绩单与置信度分数分开。所以我可以将其导出到文本文件。我该怎么做?
该输出是单词置信度。输出中应该有一个包含全文的条目,很可能在您的列表中较高的位置。
要将输出压缩为仅转录本,请删除选项 word_confidence=True
和 timestamps=True
。