File size: 5,200 Bytes
d0a9d39 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | ---
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)** 等多种任务。
[](https://www.python.org/)
[](https://pytorch.org/)
[](LICENSE)
[]()
---
## ✨ 主要功能
| 功能 | 描述 | 预训练模型 |
|------|------|------------|
| 🎙️ **语音识别 (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 支持一下!
|