python - 如何分离 JSON 数据
问题描述
我正在尝试在 python 中制作一个简单的 SR 程序来识别语音。我为此使用了 IBM 云的 api,但遇到了一些问题。
import json;
from os.path import join, dirname
from ibm_watson import SpeechToTextV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('KEY')
speech_to_text = SpeechToTextV1(
authenticator=authenticator
)
speech_to_text.set_service_url('URL')
with open(join(dirname(__file__), './.', 'recording.mp3'),
'rb') as audio_file:
speech_recognition_results = speech_to_text.recognize(
audio=audio_file,
content_type='audio/mp3',
word_alternatives_threshold=0.9,
keywords=['um', 'uh', 'like'],
keywords_threshold=0.5
).get_result()
print(json.dumps(speech_recognition_results, indent=2))
这段代码工作得很好,但它是我遇到问题的输出。
{
"result_index": 0,
"results": [
{
"final": true,
"alternatives": [
{
"transcript": "hello Ryan how are you today ",
"confidence": 0.73
}
],
"word_alternatives": [
{
"start_time": 0.19,
"end_time": 0.45,
"alternatives": [
{
"word": "hello",
"confidence": 0.93
}
]
},
{
"start_time": 0.45,
"end_time": 0.99,
"alternatives": [
{
"word": "Ryan",
"confidence": 0.92
}
]
},
{
"start_time": 1.12,
"end_time": 1.31,
"alternatives": [
{
"word": "how",
"confidence": 0.98
}
]
},
{
"start_time": 1.31,
"end_time": 1.41,
"alternatives": [
{
"word": "are",
"confidence": 0.98
}
]
},
{
"start_time": 1.41,
"end_time": 1.61,
"alternatives": [
{
"word": "you",
"confidence": 0.98
}
]
},
{
"start_time": 1.61,
"end_time": 2.04,
"alternatives": [
{
"word": "today",
"confidence": 0.99
}
]
}
],
"keywords_result": {}
}
]
}
我要做的就是将显示整个成绩单的部分隔离为变量之类的东西。我该怎么做?
解决方案
推荐阅读
- flutter - Flutter 中的 statefulWidget 中的屏幕未更新
- swift - 如何设置新值以更改我的 Story 应用程序的问题
- sql - 基于列从SQL中的一行生成多行
- excel - 更新“vlookup”值时如何更新另一个单元格值?
- javascript - D3力有向图:拖动时节点不停留在鼠标位置
- mongodb - 如何在 mongo shell forEach 中运行嵌套查询?
- flutter - 我如何在颤振中进行第二次排序
- typescript - rabbitmq 消费函数/channel.ack
- azure - 关于 cmdlet 'Get-AzKeyVaultSecret' SecretValueText 中的重大更改的警告已弃用 Az4.6.1
- cmake - ld: 找不到 -lnetcdf 的库