如何从 Python 的输出中打印特定的字典键 [不工作]
python 476
原文标题 :How to Print a specific dictionary-key from output in Python [not working]
我编写了这段代码,使用 Deepgram 将音频转换为文本,并在结果中仅打印 Dictionary 中的转录文本。我正在使用这段代码:
response = await dg_client.transcription.prerecorded(source, options)
print(json.dumps(response, indent=4))
print(response.keys())
print(response['results']['channels']['alternatives']['transcript'])
但这一个不起作用。我删除了最后两个键( [‘alternatives’][‘transcript’] ),然后它就可以工作了。这是输出中的字典:
"results": {
"channels": [
{
"alternatives": [
{
"transcript": "Yep. I said it before, and I'll say it again. Life moves pretty fast. You don't stop and look around once in a while. You could miss it.",
"confidence": 0.9935537
}]
请帮忙,提前谢谢!