调用函数时遇到问题音频配置.FromWavFileInput通过python库

2024-10-01 00:19:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Azure认知语音服务处理.wav文件。我正在使用下面的脚本。当我试图通过调用AudioConfig.FromWavFileInput()来设置wav文件时,出现了一个异常:“类型对象‘AudioConfig’没有属性‘FromWavFileInput’”。文档显示该函数存在,至少在.net库中是这样。cognitiveservices-speech python library是否存在FromWaveFileInput?如何使用python处理音频文件?在

import azure.cognitiveservices.speech as speechsdk

speechKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
service_region = 'eastus2'

#### # Creates an instance of a speech config with specified subscription key and service region.
#### # Replace with your own subscription key and service region (e.g., "westus").
speech_config = speechsdk.SpeechConfig(subscription=speechKey, region=service_region)

audioInput = speechsdk.AudioConfig.FromWavFileInput('RainSpain.wav')

#### # Creates a recognizer with the given settings
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_input=audioInput)

Tags: 文件keyconfigservicewithspeechregioncognitive
1条回答
网友
1楼 · 发布于 2024-10-01 00:19:46

确实如你所说。我在GitHub repo ^{}上搜索了关键字AudioConfig&;FromWavFileInput,除了Java、C#和C++,没有任何关于它的Python代码。在

根据我的经验,有两种解决方法。在

    将C++代码封装为Python extension module,或与C++ /java代码通信。在
  1. 直接将Speech service REST APIs^{}一起使用,对于Python和Azure语音服务来说很简单。在

相关问题 更多 >