--- title: SpeechBrain Demo emoji: 🧠 colorFrom: blue colorTo: indigo sdk: gradio sdk_version: "4.44.0" python_version: "3.10" app_file: app.py pinned: false --- # 🧠 SpeechBrain - 全能语音处理工具包 > **SpeechBrain** 是一个基于 PyTorch 的开源语音处理工具包,支持 **语音识别 (ASR)**、**语音合成 (TTS)**、**说话人识别**、**语音增强**、**语音分离**、**语音活动检测 (VAD)** 等多种任务。 [![Python](https://img.shields.io/badge/Python-3.8%2B-blue.svg)](https://www.python.org/) [![PyTorch](https://img.shields.io/badge/PyTorch-2.1%2B-red.svg)](https://pytorch.org/) [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](LICENSE) [![Version](https://img.shields.io/badge/Version-1.1.0-orange.svg)]() --- ## ✨ 主要功能 | 功能 | 描述 | 预训练模型 | |------|------|------------| | 🎙️ **语音识别 (ASR)** | 将语音转为文字,支持多种语言 | ✅ | | 🔊 **语音合成 (TTS)** | 将文字转为自然语音 | ✅ | | 👤 **说话人识别** | 识别说话人身份 | ✅ | | 🎵 **语音增强** | 降噪、去混响 | ✅ | | 🎧 **语音分离** | 分离混合音频中的多个声源 | ✅ | | 📊 **语音活动检测** | 检测语音段/非语音段 | ✅ | | 📝 **说话人日志** | 谁在什么时候说话 | ✅ | | 🌐 **翻译 (ST)** | 语音到文本翻译 | ✅ | --- ## 🚀 快速开始 ### 安装 ```bash # 克隆仓库 git clone https://github.com/zq-1115/demo.git cd demo # 安装依赖 pip install -r requirements.txt ``` ### 30秒体验 ```python from speechbrain.inference import EncoderDecoderASR # 下载预训练模型并转录音频 asr_model = EncoderDecoderASR.from_hparams( source="speechbrain/asr-crdnn-rnnlm-librispeech", savedir="pretrained_models/asr-crdnn-rnnlm-librispeech", ) # 转录音频文件 text = asr_model.transcribe_file("demo_audio.wav") print(f"识别结果: {text}") ``` --- ## 📂 项目结构 ``` speechbrain-develop/ ├── speechbrain/ # 核心库代码 │ ├── inference/ # 推理接口 (ASR/TTS/VAD等) │ ├── dataio/ # 数据加载与处理 │ ├── decoders/ # 解码器 (CTC/Seq2Seq等) │ ├── augment/ # 数据增强 │ ├── alignment/ # 对齐工具 │ ├── integrations/ # 集成模块 (HuggingFace/K2等) │ └── utils/ # 工具函数 ├── tests/ # 测试与示例音频 ├── demo.py # 🎯 交互式演示脚本 ├── requirements.txt # 依赖列表 └── setup.py # 安装配置 ``` --- ## 🎮 运行演示 ```bash python demo.py ``` 演示程序提供交互式菜单,可以选择: 1. **语音识别 (ASR)** — 上传音频,输出文字 2. **说话人识别** — 识别说话人 3. **语音活动检测 (VAD)** — 检测语音片段 --- ## 🔧 使用示例 ### 1. 语音识别 (ASR) ```python from speechbrain.inference import EncoderDecoderASR asr = EncoderDecoderASR.from_hparams( source="speechbrain/asr-crdnn-rnnlm-librispeech", savedir="pretrained_models/asr", ) result = asr.transcribe_file("audio.wav") print(result) # "MY FATHER HAS REVEALED THE CULPRIT'S NAME" ``` ### 2. 说话人识别 ```python from speechbrain.inference import SpeakerRecognition spk_rec = SpeakerRecognition.from_hparams( source="speechbrain/spkrec-ecapa-voxceleb", savedir="pretrained_models/spkrec", ) score, prediction = spk_rec.verify_files("spk1.wav", "spk2.wav") print(f"是同一个人吗? {'是' if prediction else '否'}") ``` ### 3. 语音活动检测 (VAD) ```python from speechbrain.inference import VAD vad = VAD.from_hparams( source="speechbrain/vad-crdnn-libriparty", savedir="pretrained_models/vad", ) boundaries = vad.get_speech_segments("audio.wav") for start, end in boundaries: print(f"语音段: {start:.2f}s - {end:.2f}s") ``` ### 4. 语音合成 (TTS) ```python from speechbrain.inference import Tacotron2 from speechbrain.inference import HIFIGAN tacotron2 = Tacotron2.from_hparams( source="speechbrain/tts-tacotron2-ljspeech", savedir="pretrained_models/tts-tacotron2", ) hifi_gan = HIFIGAN.from_hparams( source="speechbrain/tts-hifigan-ljspeech", savedir="pretrained_models/tts-hifigan", ) # 文字转语音 mel_output, mel_length, alignment = tacotron2.encode_text("Hello world") waveforms = hifi_gan.decode_batch(mel_output) torchaudio.save("output.wav", waveforms.squeeze(1), 22050) ``` --- ## 📦 依赖 - **Python** >= 3.8 - **PyTorch** >= 2.1.0 - **torchaudio** >= 2.1.0 - **transformers** >= 4.30.0 - 完整列表见 [requirements.txt](requirements.txt) --- ## 🤝 贡献 欢迎提交 Issue 和 Pull Request! --- ## 📄 许可证 本项目基于 Apache 2.0 许可证开源。详见 [LICENSE](LICENSE)。 --- ## ⭐ Star History 如果这个项目对你有帮助,请给一个 ⭐ Star 支持一下!