Microsoft 认知服务 SST 支持哪些音频格式?为什么 16 位 PCM x.wav 成功而 32 位 PCM y.wav 不成功?

What audio formats are supported by Microsoft cognitive services SST? Why does 16-bit PCM x.wav succeed while 32-bit PCM y.wav doesn't?

我正在尝试通过 python API 使用 Microsoft 认知服务解决语音到文本问题。我有两个文件,harvard.wavOptagelse_0.wav,我想转录它们,但我只成功了 harvard.wav

文件 harvard.wav 具有以下属性:

{'filename': 'harvard.wav', 'nb_streams': '1', 'format_name': 'wav', 'format_long_name': 'WAV / WAVE (Waveform Audio)', 'start_time': 'N/A', 'duration': '18.356190', 'size': '3249924.000000', 'bit_rate': '1411200.000000', 'TAG': {'encoder': 'Adobe Audition CC 2018.0 (Windows)', 'date': '2018-03-03', 'creation_time': '18\:52\:53', 'time_reference': '0'}, 'index': '0', 'codec_name': 'pcm_s16le', 'codec_long_name': 'PCM signed 16-bit little-endian', 'codec_type': 'audio', 'codec_time_base': '1/44100', 'codec_tag_string': '[1][0][0][0]', 'codec_tag': '0x0001', 'sample_rate': '44100.000000', 'channels': '2', 'bits_per_sample': '16', 'avg_frame_rate': '0/0', 'time_base': '1/44100'}

而 Optagelse_0.wav 有:

{'filename': 'Optagelse_0.wav', 'nb_streams': '1', 'format_name': 'wav', 'format_long_name': 'WAV / WAVE (Waveform Audio)', 'start_time': 'N/A', 'duration': '29.056000', 'size': '5578796.000000', 'bit_rate': '1536000.000000', 'index': '0', 'codec_name': 'pcm_s32le', 'codec_long_name': 'PCM signed 32-bit little-endian', 'codec_type': 'audio', 'codec_time_base': '1/48000', 'codec_tag_string': '[1][0][0][0]', 'codec_tag': '0x0001', 'sample_rate': '48000.000000', 'channels': '1', 'bits_per_sample': '32', 'avg_frame_rate': '0/0', 'time_base': '1/48000'}

我已经尝试根据更改harvard.wav的采样率 但没有任何改善。

speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
audio_config = speechsdk.audio.AudioConfig(filename='sound.wav')
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
result = speech_recognizer.recognize_once()

# Check the result
if result.reason == speechsdk.ResultReason.RecognizedSpeech:
    print("Recognized: {}".format(result.text))
elif result.reason == speechsdk.ResultReason.NoMatch:
    print("No speech could be recognized: {}".format(result.no_match_details))
elif result.reason == speechsdk.ResultReason.Canceled:
    cancellation_details = result.cancellation_details
    print("Speech Recognition canceled: {}".format(cancellation_details.reason))
    if cancellation_details.reason == speechsdk.CancellationReason.Error:
        print("Error details: {}".format(cancellation_details.error_details))

我希望得到一个转录的打印输出,但我得到了错误

Speech Recognition canceled: CancellationReason.Error
Error details: Invalid parameter or unsupported audio format in the request. Response text:{"Duration":0,"Offset":0,"RecognitionStatus":"BadRequest"}

根据 Azure documentation,您需要 16 位 PCM,而 Optalgese.wav 是您问题中的 32 位 - " 'codec_long_name': 'PCM signed 32-bit little-endian'"

OP 能够使用 ffmpeg

将音频文件从 32 位更改为 16 位
 ffmpeg -i Optagelse.wav -acodec pcm_s16le Opt_pcm_16.wav