gpt4 book ai didi

python - Google 语音转文本 API 结果为空

转载 作者:太空宇宙 更新时间:2023-11-03 21:35:20 25 4
gpt4 key购买 nike

我正在使用云语音转文本 api 将音频文件转换为文本文件。我正在使用 python 执行它,下面是代码。

import io
import os

os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="D:\\Sentiment_Analysis\\My Project 59503-717155d6fb4a.json"

# Imports the Google Cloud client library
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types

# Instantiates a client
client = speech.SpeechClient()

# The name of the audio file to transcribe
file_name = os.path.join(os.path.dirname('D:\CallADoc_VoiceImplementation\audioclip154173607416598.amr'),'CallADoc_VoiceImplementation','audioclip154173607416598.amr')

# Loads the audio into memory
with io.open(file_name, 'rb') as audio_file: content = audio_file.read()
audio = types.RecognitionAudio(content=content)

config = types.RecognitionConfig(encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,sample_rate_hertz=16000,language_code='en-IN')

# Detects speech in the audio file
response = client.recognize(config, audio)

for result in response.results: print('Transcript: {}'.format(result.alternatives[0].transcript))

当我执行名为“audio.raw”的示例/测试音频文件时,音频正在转换,结果如下。

runfile('C:/Users/sandesh.p/CallADoc/GoogleSpeechtoText.py', wdir='C:/Users/sandesh.p/CallADoc')
Transcript: how old is the Brooklyn Bridge

但是对于相同的代码,我正在录制音频并尝试进行转换,它给出了如下所示的空结果:

runfile('C:/Users/sandesh.p/CallADoc/GoogleSpeechtoText.py', wdir='C:/Users/sandesh.p/CallADoc')

过去两天我一直在尝试解决这个问题,请帮助我解决这个问题。

最佳答案

尝试遵循troubleshooting steps使您的音频具有适当的设置。

例如,您的音频文件将具有以下设置,需要这些设置才能获得更好的效果:

Encoding: FLAC
Channels: 1 @ 16-bit
Sampleratehertz: 16000Hz

关于python - Google 语音转文本 API 结果为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53274198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com