使用Azure语音服务,我正在尝试转录一堆wav文件(以PCMU (又名mu格式)压缩)。
我根据下面引用的文章编写了以下代码。这段代码有时能很好地处理少量文件,但我总是在循环一个更大的文件列表(~50)时得到Segmentation fault
错误,并且它不会在同一个文件上中断(可能是第2、第15或第27)。
此外,在运行一个文件子集时,代码解压缩部分的转录结果似乎是一样的,这让我怀疑Microsoft推荐的解压缩方法是否有效。
import azure.cognitiveservices.speech as speechsdk
def azurespeech_transcribe(audio_filename):
class BinaryFileReaderCallback(speechsdk.audio.PullAudioInputStreamCallback):
def __init__(self, filename: str):
super().__init__()
self._file_h = open(filename, "rb")
def read(self, buffer: memoryview) -> int:
try:
size = buffer.nbytes
frames = self._file_h.read(size)
buffer[:len(frames)] = frames
return len(frames)
except Exception as ex:
print('Exception in `read`: {}'.format(ex))
raise
def close(self) -> None:
try:
self._file_h.close()
except Exception as ex:
print('Exception in `close`: {}'.format(ex))
raise
compressed_format = speechsdk.audio.AudioStreamFormat(
compressed_stream_format=speechsdk.AudioStreamContainerFormat.MULAW
)
callback = BinaryFileReaderCallback(filename=audio_filename)
stream = speechsdk.audio.PullAudioInputStream(
stream_format=compressed_format,
pull_stream_callback=callback
)
speech_config = speechsdk.SpeechConfig(
subscription="<my_subscription_key>",
region="<my_region>",
speech_recognition_language="en-CA"
)
audio_config = speechsdk.audio.AudioConfig(stream=stream)
speech_recognizer = speechsdk.SpeechRecognizer(speech_config, audio_config)
result = speech_recognizer.recognize_once()
return result.text
代码正在WSL上运行。
我已经试过了:
faulthandler
模块记录更有意义的错误resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))
参考资料:
发布于 2022-11-01 10:40:28
我试图处理类似的数据集,但没有发现任何分割错误。使用定价层检查订阅和部署模式。实现了与自定义语音的文本翻译器,并在切分中发挥了一定的作用。
分割因位置、位置和定价层的不同而不同。
在运行语法之后,我没有发现任何分割错误,因为定价层适合于数据量。
发布于 2022-11-29 22:22:27
从1.24.0SpeetSDK版本(及以后)开始,您可以使用AudioStreamWaveFormat (https://learn.microsoft.com/en-us/python/api/azure-cognitiveservices-speech/azure.cognitiveservices.speech.audiostreamwaveformat?view=azure-python)将ALAW/MULAW编码的数据直接流到语音服务(不需要Gstreamer)。这样,涉及的复杂性就更少了(没有Gstreamer)。
encoded_format = msspeech.audio.AudioStreamFormat(samples_per_second=16000, bits_per_sample=16,
channels=1, wave_stream_format=msspeech.AudioStreamWaveFormat.MULAW)
https://stackoverflow.com/questions/74197867
复制相似问题