本文主要是介绍librosa 语音识别 学习笔记,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
不错的功能介绍
librosa安装
语音识别
不错的功能介绍
librosa,一个很有趣的 Python 库! - 简书
音频转特征向量
GitHub - librosa/librosa: Python library for audio and music analysis
librosa安装
2024.04.27 测试ok Win11系统
pip install librosa
import osimport numpy as np
from transformers import Wav2Vec2Processor, Wav2Vec2Model
import torchimport librosadef load_example_input(audio_path, processor=None):if processor is None:processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-base-960h")speech_array, sampling_rate = librosa.load(os.path.join(audio_path), sr=16000)audio_feature = np.squeeze(processor(speech_array, sampling_rate=sampling_rate).input_values)audio_feature = np.reshape(audio_feature, (-1, audio_feature.shape[0]))return torch.FloatTensor(audio_feature)audio_path=r'demo/wav/man.wav'load_example_input(audio_path)
语音识别
pip install SpeechRecognition
pip install pyaudio
import librosa
import speech_recognition as sr# 录制音频
r = sr.Recognizer()
with sr.Microphone() as source:print("请开始说话...")audio = r.listen(source)# 将音频转换为文本
try:text = r.recognize_google(audio)print("识别结果:", text)
except sr.UnknownValueError:print("无法识别音频")
except sr.RequestError as e:print(f"请求出错:{e}")
这篇关于librosa 语音识别 学习笔记的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!