小编Psy*_*rdy的帖子

如何停用 OpenAI Whisper 对超过 30 秒的音频输入的标准化?(转录填充词)

OpenAI 的 Whisper 可以提供漂亮、干净的文字记录。现在我希望它能生成更多原始记录,其中还包含填充词(ah、mh、mhm、uh、oh 等)。这里的帖子告诉我,可以通过将标准化设置为 false: https: //huggingface.co/spaces/openai/whisper/discussions/30

我设法使用了这段代码,但我只得到了 30 秒的耳语转录。如何让它处理更长的音频文件?

请注意,我是一个耳语和Python的初学者。

到目前为止我所做的:我主要使用https://huggingface.co/spaces/openai/whisper/discussions/30中的代码因为我不想使用虚拟数据集,所以我使用 librosa 加载本地 mp3 。我想还有其他方法可以做到这一点,我对此持开放态度。

据我了解,指示耳语处理器对于停用标准化是必要的。因此,这里使用的不是耳语 ( import whisper) 而是耳语 via transformers。相关开关是normalize = False

我的代码(myscript.py):

from transformers import WhisperProcessor, WhisperForConditionalGeneration
import librosa

speech, _ = librosa.load("myaudio.mp3", sr=16000, mono=True)

processor = WhisperProcessor.from_pretrained("openai/whisper-large")
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large")

model.config.forced_decoder_ids = processor.get_decoder_prompt_ids(language = "de", task = "transcribe")
input_features = processor(speech, return_tensors="pt", sampling_rate=16000).input_features 
predicted_ids = model.generate(input_features)
transcription = processor.batch_decode(predicted_ids, skip_special_tokens = True, normalize = False)

print(transcription)
Run Code Online (Sandbox Code Playgroud)

到目前为止效果很好。但是,仅转录前 30 …

python speech-recognition python-3.x openai-whisper

5
推荐指数
1
解决办法
1885
查看次数