开始使用免费开始使用

自动语音识别

在本练习中,您将使用 AI 自动将音频转写为文本!您将再次使用 VCTK 语料库,其中包含约 44 小时由不同口音的英语母语者录制的语音。您将使用 OpenAI 的 Whisper tiny 模型(仅含 37M 参数)来预处理 VCTK 音频数据,并生成对应的文本。

音频预处理器(processor)和 WhisperForConditionalGeneration 模块已加载。一个音频样本数据点(sample)也已提供。

本练习是课程的一部分

使用 Hugging Face 的多模态模型

查看课程

练习说明

  • 使用 openai/whisper-tiny 检查点加载 WhisperForConditionalGeneration 预训练模型。
  • 以要求的 16000 采样率预处理 sample 数据点。
  • 使用预处理输入的 .input_features 属性,从模型中生成标记。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Load the pretrained model
model = ____
model.config.forced_decoder_ids=None

# Preprocess the sample audio
input_preprocessed = ____(____, sampling_rate=____, return_tensors="pt", return_attention_mask=True)

# Generate the IDs of the recognized tokens
predicted_ids = ____
transcription = processor.decode(predicted_ids[0], skip_special_tokens=True)
print(transcription)
编辑并运行代码