我不断收到此错误 InvalidArgument: 400
在 google Speech-to-text 中,问题似乎是我使用 2 声道音频(立体声),而 API 正在等待(单声道)中的 wav。
如果我在音频编辑器中转换文件,它可能会工作,但我不能使用音频编辑器来转换一批文件。有没有办法在 Python 或 Google Cloud 中更改音频类型。
注意:我已经尝试过使用“wave 模块”,但我一直收到错误 #7,因为文件类型无法识别(我无法使用 Python 中的模块 wave 读取 wav 文件)
-ERROR- InvalidArgument: 400 Must use single channel (mono) audio, but WAV header indicates 2 channels.
最佳答案
假设您使用的是 google-cloud-speech 库,您可以使用 audio_channel_count
您的 RecognitionConfig
中的属性(property)并指定输入音频数据中的 channel 数(默认为一个 channel (单声道))。你可以这样做:
from google.cloud import speech
client = speech.SpeechClient()
results = client.recognize(
audio = speech.types.RecognitionAudio(
uri = 'gs://your-bucket/recording.wav',
),
config = speech.types.RecognitionConfig(
encoding = 'LINEAR16',
language_code = 'en-US',
sample_rate_hertz = 44100,
audio_channel_count = 2,
),
)
见API doc了解更多信息。
关于python - Google Speech-to-text API,InvalidArgument : 400 Must use single channel (mono),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55106509/