mirror of
https://github.com/FunAudioLLM/SenseVoice.git
synced 2025-09-15 15:08:35 +08:00
commit
ace1d34b69
100
README.md
100
README.md
@ -1,4 +1,4 @@
|
||||
([简体中文](./README_zh.md)|English)
|
||||
([简体中文](./README_zh.md)|English|[日本語](./README_ja.md))
|
||||
|
||||
|
||||
# Introduction
|
||||
@ -11,8 +11,7 @@ SenseVoice is a speech foundation model with multiple speech understanding capab
|
||||
|
||||
<div align="center">
|
||||
<h4>
|
||||
<a href="https://www.modelscope.cn/studios/iic/SenseVoice"> Online Demo </a>
|
||||
|<a href="https://fun-audio-llm.github.io/"> Homepage </a>
|
||||
<a href="https://fun-audio-llm.github.io/"> Homepage </a>
|
||||
|<a href="#What's News"> What's News </a>
|
||||
|<a href="#Benchmarks"> Benchmarks </a>
|
||||
|<a href="#Install"> Install </a>
|
||||
@ -23,11 +22,15 @@ SenseVoice is a speech foundation model with multiple speech understanding capab
|
||||
Model Zoo:
|
||||
[modelscope](https://www.modelscope.cn/models/iic/SenseVoiceSmall), [huggingface](https://huggingface.co/FunAudioLLM/SenseVoiceSmall)
|
||||
|
||||
Online Demo:
|
||||
[modelscope demo](https://www.modelscope.cn/studios/iic/SenseVoice), [huggingface space](https://huggingface.co/spaces/FunAudioLLM/SenseVoice)
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<a name="Highligts"></a>
|
||||
# Highligts 🎯
|
||||
# Highlights 🎯
|
||||
**SenseVoice** focuses on high-accuracy multilingual speech recognition, speech emotion recognition, and audio event detection.
|
||||
- **Multilingual Speech Recognition:** Trained with over 400,000 hours of data, supporting more than 50 languages, the recognition performance surpasses that of the Whisper model.
|
||||
- **Rich transcribe:**
|
||||
@ -95,61 +98,55 @@ pip install -r requirements.txt
|
||||
|
||||
## Inference
|
||||
|
||||
### Method 1
|
||||
|
||||
```python
|
||||
from model import SenseVoiceSmall
|
||||
|
||||
model_dir = "iic/SenseVoiceSmall"
|
||||
m, kwargs = SenseVoiceSmall.from_pretrained(model=model_dir)
|
||||
|
||||
|
||||
res = m.inference(
|
||||
data_in="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav",
|
||||
language="zh", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=False,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
print(res)
|
||||
```
|
||||
|
||||
### Method 2
|
||||
Supports input of audio in any format and of any duration.
|
||||
|
||||
```python
|
||||
from funasr import AutoModel
|
||||
from funasr.utils.postprocess_utils import rich_transcription_postprocess
|
||||
|
||||
model_dir = "iic/SenseVoiceSmall"
|
||||
input_file = (
|
||||
"https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav"
|
||||
|
||||
|
||||
model = AutoModel(
|
||||
model=model_dir,
|
||||
trust_remote_code=True,
|
||||
remote_code="./model.py",
|
||||
vad_model="fsmn-vad",
|
||||
vad_kwargs={"max_single_segment_time": 30000},
|
||||
device="cuda:0",
|
||||
)
|
||||
|
||||
model = AutoModel(model=model_dir,
|
||||
vad_model="fsmn-vad",
|
||||
vad_kwargs={"max_single_segment_time": 30000},
|
||||
trust_remote_code=True, device="cuda:0")
|
||||
|
||||
# en
|
||||
res = model.generate(
|
||||
input=input_file,
|
||||
input=f"{model.model_path}/example/en.mp3",
|
||||
cache={},
|
||||
language="zh", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=False,
|
||||
batch_size_s=0,
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=True,
|
||||
batch_size_s=60,
|
||||
merge_vad=True, #
|
||||
merge_length_s=15,
|
||||
)
|
||||
|
||||
text = rich_transcription_postprocess(res[0]["text"])
|
||||
|
||||
print(text)
|
||||
```
|
||||
|
||||
The funasr version has integrated the VAD (Voice Activity Detection) model and supports audio input of any duration, with `batch_size_s` in seconds.
|
||||
If all inputs are short audios, and batch inference is needed to speed up inference efficiency, the VAD model can be removed, and `batch_size` can be set accordingly.
|
||||
Parameter Description:
|
||||
- `model_dir`: The name of the model, or the path to the model on the local disk.
|
||||
- `trust_remote_code`:
|
||||
- When `True`, it means that the model's code implementation is loaded from `remote_code`, which specifies the exact location of the `model` code (for example, `model.py` in the current directory). It supports absolute paths, relative paths, and network URLs.
|
||||
- When `False`, it indicates that the model's code implementation is the integrated version within [FunASR](https://github.com/modelscope/FunASR). At this time, modifications made to `model.py` in the current directory will not be effective, as the version loaded is the internal one from FunASR. For the model code, [click here to view](https://github.com/modelscope/FunASR/tree/main/funasr/models/sense_voice).
|
||||
- `vad_model`: This indicates the activation of VAD (Voice Activity Detection). The purpose of VAD is to split long audio into shorter clips. In this case, the inference time includes both VAD and SenseVoice total consumption, and represents the end-to-end latency. If you wish to test the SenseVoice model's inference time separately, the VAD model can be disabled.
|
||||
- `vad_kwargs`: Specifies the configurations for the VAD model. `max_single_segment_time`: denotes the maximum duration for audio segmentation by the `vad_model`, with the unit being milliseconds (ms).
|
||||
- `use_itn`: Whether the output result includes punctuation and inverse text normalization.
|
||||
- `batch_size_s`: Indicates the use of dynamic batching, where the total duration of audio in the batch is measured in seconds (s).
|
||||
- `merge_vad`: Whether to merge short audio fragments segmented by the VAD model, with the merged length being `merge_length_s`, in seconds (s).
|
||||
|
||||
If all inputs are short audios (<30s), and batch inference is needed to speed up inference efficiency, the VAD model can be removed, and `batch_size` can be set accordingly.
|
||||
```python
|
||||
model = AutoModel(model=model_dir, trust_remote_code=True, device="cuda:0")
|
||||
|
||||
res = model.generate(
|
||||
input=input_file,
|
||||
input=f"{model.model_path}/example/en.mp3",
|
||||
cache={},
|
||||
language="zh", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=False,
|
||||
@ -159,9 +156,30 @@ res = model.generate(
|
||||
|
||||
For more usage, please refer to [docs](https://github.com/modelscope/FunASR/blob/main/docs/tutorial/README.md)
|
||||
|
||||
### Inference directly
|
||||
|
||||
Supports input of audio in any format, with an input duration limit of 30 seconds or less.
|
||||
|
||||
```python
|
||||
from model import SenseVoiceSmall
|
||||
from funasr.utils.postprocess_utils import rich_transcription_postprocess
|
||||
|
||||
model_dir = "iic/SenseVoiceSmall"
|
||||
m, kwargs = SenseVoiceSmall.from_pretrained(model=model_dir, device="cuda:0")
|
||||
|
||||
|
||||
### Export and Test
|
||||
res = m.inference(
|
||||
data_in=f"{kwargs['model_path']}/example/en.mp3",
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=False,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
text = rich_transcription_postprocess(res[0][0]["text"])
|
||||
print(text)
|
||||
```
|
||||
|
||||
### Export and Test (*On going*)
|
||||
|
||||
```python
|
||||
# pip3 install -U funasr-onnx
|
||||
|
||||
246
README_ja.md
Normal file
246
README_ja.md
Normal file
@ -0,0 +1,246 @@
|
||||
# SenseVoice
|
||||
|
||||
「[简体中文](./README_zh.md)」|「[English](./README.md)」|「日本語」
|
||||
|
||||
SenseVoiceは、音声認識(ASR)、言語識別(LID)、音声感情認識(SER)、および音響イベント分類(AEC)または音響イベント検出(AED)を含む音声理解能力を備えた音声基盤モデルです。本プロジェクトでは、SenseVoiceモデルの紹介と、複数のタスクテストセットでのベンチマーク、およびモデルの体験に必要な環境のインストールと推論方法を提供します。
|
||||
|
||||
<div align="center">
|
||||
<img src="image/sensevoice2.png">
|
||||
|
||||
[//]: # (<div align="center"><img src="image/sensevoice2.png" width="700"/> </div>)
|
||||
|
||||
<h4>
|
||||
<a href="#What's New"> ドキュメントホーム </a>
|
||||
|<a href="#核心功能"> コア機能 </a>
|
||||
</h4>
|
||||
<h4>
|
||||
<a href="#On Going"> 最新情報 </a>
|
||||
|<a href="#Benchmark"> ベンチマーク </a>
|
||||
|<a href="#环境安装"> 環境インストール </a>
|
||||
|<a href="#用法教程"> 使用方法 </a>
|
||||
|<a href="#联系我们"> お問い合わせ </a>
|
||||
</h4>
|
||||
|
||||
モデルリポジトリ:[modelscope](https://www.modelscope.cn/models/iic/SenseVoiceSmall),[huggingface](https://huggingface.co/FunAudioLLM/SenseVoiceSmall)
|
||||
|
||||
オンライン体験:
|
||||
[modelscope demo](https://www.modelscope.cn/studios/iic/SenseVoice), [huggingface space](https://huggingface.co/spaces/FunAudioLLM/SenseVoice)
|
||||
|
||||
</div>
|
||||
|
||||
<a name="核心功能"></a>
|
||||
# コア機能 🎯
|
||||
**SenseVoice**は、高精度な多言語音声認識、感情認識、および音声イベント検出に焦点を当てています。
|
||||
- **多言語認識:** 40万時間以上のデータを使用してトレーニングされ、50以上の言語をサポートし、認識性能はWhisperモデルを上回ります。
|
||||
- **リッチテキスト認識:**
|
||||
- 優れた感情認識能力を持ち、テストデータで現在の最良の感情認識モデルの効果を達成および上回ります。
|
||||
- 音声イベント検出能力を提供し、音楽、拍手、笑い声、泣き声、咳、くしゃみなどのさまざまな一般的な人間とコンピュータのインタラクションイベントを検出します。
|
||||
- **効率的な推論:** SenseVoice-Smallモデルは非自己回帰エンドツーエンドフレームワークを採用しており、推論遅延が非常に低く、10秒の音声の推論に70msしかかかりません。Whisper-Largeより15倍高速です。
|
||||
- **簡単な微調整:** 便利な微調整スクリプトと戦略を提供し、ユーザーがビジネスシナリオに応じてロングテールサンプルの問題を簡単に解決できるようにします。
|
||||
- **サービス展開:** マルチコンカレントリクエストをサポートする完全なサービス展開パイプラインを提供し、クライアントサイドの言語にはPython、C++、HTML、Java、C#などがあります。
|
||||
|
||||
<a name="最新动态"></a>
|
||||
# 最新情報 🔥
|
||||
- 2024/7: [SenseVoice-Small](https://www.modelscope.cn/models/iic/SenseVoiceSmall) 多言語音声理解モデルがオープンソース化されました。中国語、広東語、英語、日本語、韓国語の多言語音声認識、感情認識、およびイベント検出能力をサポートし、非常に低い推論遅延を実現しています。
|
||||
- 2024/7: CosyVoiceは自然な音声生成に取り組んでおり、多言語、音色、感情制御をサポートします。多言語音声生成、ゼロショット音声生成、クロスランゲージ音声クローン、および指示に従う能力に優れています。[CosyVoice repo](https://github.com/FunAudioLLM/CosyVoice) and [CosyVoice オンライン体験](https://www.modelscope.cn/studios/iic/CosyVoice-300M).
|
||||
- 2024/7: [FunASR](https://github.com/modelscope/FunASR) は、音声認識(ASR)、音声活動検出(VAD)、句読点復元、言語モデル、話者検証、話者分離、およびマルチトーカーASRなどの機能を提供する基本的な音声認識ツールキットです。
|
||||
|
||||
<a name="Benchmarks"></a>
|
||||
# ベンチマーク 📝
|
||||
|
||||
## 多言語音声認識
|
||||
|
||||
オープンソースのベンチマークデータセット(AISHELL-1、AISHELL-2、Wenetspeech、Librispeech、Common Voiceを含む)でSenseVoiceとWhisperの多言語音声認識性能と推論効率を比較しました。中国語と広東語の認識効果において、SenseVoice-Smallモデルは明らかな効果の優位性を持っています。
|
||||
|
||||
<div align="center">
|
||||
<img src="image/asr_results1.png" width="400" /><img src="image/asr_results2.png" width="400" />
|
||||
</div>
|
||||
|
||||
## 感情認識
|
||||
|
||||
現在、広く使用されている感情認識のテスト指標と方法が不足しているため、複数のテストセットでさまざまな指標をテストし、最近のベンチマークの複数の結果と包括的に比較しました。選択されたテストセットには、中国語/英語の両方の言語と、パフォーマンス、映画、自然な会話などのさまざまなスタイルのデータが含まれています。ターゲットデータの微調整を行わない前提で、SenseVoiceはテストデータで現在の最良の感情認識モデルの効果を達成および上回ることができました。
|
||||
|
||||
<div align="center">
|
||||
<img src="image/ser_table.png" width="1000" />
|
||||
</div>
|
||||
|
||||
さらに、テストセットで複数のオープンソースの感情認識モデルを比較し、結果はSenseVoice-Largeモデルがほぼすべてのデータで最良の効果を達成し、SenseVoice-Smallモデルも多数のデータセットで他のオープンソースモデルを上回る効果を達成したことを示しています。
|
||||
|
||||
<div align="center">
|
||||
<img src="image/ser_figure.png" width="500" />
|
||||
</div>
|
||||
|
||||
## イベント検出
|
||||
|
||||
SenseVoiceは音声データのみでトレーニングされていますが、イベント検出モデルとして単独で使用することもできます。環境音分類ESC-50データセットで、現在業界で広く使用されているBEATSおよびPANNモデルの効果と比較しました。SenseVoiceモデルはこれらのタスクで良好な効果を達成しましたが、トレーニングデータとトレーニング方法の制約により、イベント分類の効果は専門のイベント検出モデルと比較してまだ一定の差があります。
|
||||
|
||||
<div align="center">
|
||||
<img src="image/aed_figure.png" width="500" />
|
||||
</div>
|
||||
|
||||
## 推論効率
|
||||
|
||||
SenseVoice-smallモデルは非自己回帰エンドツーエンドアーキテクチャを採用しており、推論遅延が非常に低いです。Whisper-Smallモデルと同等のパラメータ量で、Whisper-Smallモデルより5倍高速で、Whisper-Largeモデルより15倍高速です。同時に、SenseVoice-smallモデルは音声の長さが増加しても、推論時間に明らかな増加はありません。
|
||||
|
||||
<div align="center">
|
||||
<img src="image/inference.png" width="1000" />
|
||||
</div>
|
||||
|
||||
<a name="环境安装"></a>
|
||||
# 環境インストール 🐍
|
||||
|
||||
```shell
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
<a name="用法教程"></a>
|
||||
# 使用方法 🛠️
|
||||
|
||||
## 推論
|
||||
|
||||
任意の形式の音声入力をサポートし、任意の長さの入力をサポートします。
|
||||
|
||||
```python
|
||||
from funasr import AutoModel
|
||||
from funasr.utils.postprocess_utils import rich_transcription_postprocess
|
||||
|
||||
model_dir = "iic/SenseVoiceSmall"
|
||||
|
||||
|
||||
model = AutoModel(
|
||||
model=model_dir,
|
||||
trust_remote_code=True,
|
||||
remote_code="./model.py",
|
||||
vad_model="fsmn-vad",
|
||||
vad_kwargs={"max_single_segment_time": 30000},
|
||||
device="cuda:0",
|
||||
)
|
||||
|
||||
# en
|
||||
res = model.generate(
|
||||
input=f"{model.model_path}/example/en.mp3",
|
||||
cache={},
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=True,
|
||||
batch_size_s=60,
|
||||
merge_vad=True, #
|
||||
merge_length_s=15,
|
||||
)
|
||||
text = rich_transcription_postprocess(res[0]["text"])
|
||||
print(text)
|
||||
```
|
||||
パラメータの説明:
|
||||
- `model_dir`:モデル名、またはローカルディスク上のモデルパス。
|
||||
- `trust_remote_code`:
|
||||
- `True`は、modelコードの実装が`remote_code`からロードされることを意味し、`remote_code`は`model`コードの正確な位置を指定します(例:現在のディレクトリの`model.py`)。絶対パス、相対パス、およびネットワークURLをサポートします。
|
||||
- `False`は、modelコードの実装が[FunASR](https://github.com/modelscope/FunASR)内部に統合されたバージョンであることを意味し、この場合、現在のディレクトリの`model.py`を変更しても効果がありません。FunASR内部バージョンがロードされるためです。モデルコード[こちらを参照](https://github.com/modelscope/FunASR/tree/main/funasr/models/sense_voice)。
|
||||
- `vad_model`:VAD(音声活動検出)を有効にすることを示します。VADの目的は、長い音声を短いクリップに分割することです。この場合、推論時間にはVADとSenseVoiceの合計消費が含まれ、エンドツーエンドの遅延を表します。SenseVoiceモデルの推論時間を個別にテストする場合は、VADモデルを無効にできます。
|
||||
- `vad_kwargs`:VADモデルの設定を指定します。`max_single_segment_time`:`vad_model`による音声セグメントの最大長を示し、単位はミリ秒(ms)です。
|
||||
- `use_itn`:出力結果に句読点と逆テキスト正規化が含まれるかどうか。
|
||||
- `batch_size_s`:動的バッチの使用を示し、バッチ内の音声の合計長を秒(s)で測定します。
|
||||
- `merge_vad`:VADモデルによって分割された短い音声フラグメントをマージするかどうか。マージ後の長さは`merge_length_s`で、単位は秒(s)です。
|
||||
|
||||
すべての入力が短い音声(30秒未満)であり、バッチ推論が必要な場合、推論効率を向上させるためにVADモデルを削除し、`batch_size`を設定できます。
|
||||
|
||||
```python
|
||||
model = AutoModel(model=model_dir, trust_remote_code=True, device="cuda:0")
|
||||
|
||||
res = model.generate(
|
||||
input=f"{model.model_path}/example/en.mp3",
|
||||
cache={},
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=True,
|
||||
batch_size=64,
|
||||
)
|
||||
```
|
||||
|
||||
詳細な使用方法については、[ドキュメント](https://github.com/modelscope/FunASR/blob/main/docs/tutorial/README.md)を参照してください。
|
||||
|
||||
### 直接推論
|
||||
|
||||
任意の形式の音声入力をサポートし、入力音声の長さは30秒以下に制限されます。
|
||||
|
||||
```python
|
||||
from model import SenseVoiceSmall
|
||||
from funasr.utils.postprocess_utils import rich_transcription_postprocess
|
||||
|
||||
model_dir = "iic/SenseVoiceSmall"
|
||||
m, kwargs = SenseVoiceSmall.from_pretrained(model=model_dir, device="cuda:0")
|
||||
|
||||
|
||||
res = m.inference(
|
||||
data_in=f"{kwargs['model_path']}/example/en.mp3",
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=False,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
text = rich_transcription_postprocess(res[0][0]["text"])
|
||||
print(text)
|
||||
```
|
||||
|
||||
## サービス展開
|
||||
|
||||
未完了
|
||||
|
||||
### エクスポートとテスト(*進行中*)
|
||||
|
||||
```python
|
||||
# pip3 install -U funasr-onnx
|
||||
from funasr_onnx import SenseVoiceSmall
|
||||
|
||||
model_dir = "iic/SenseVoiceSmall"
|
||||
model = SenseVoiceSmall(model_dir, batch_size=1, quantize=True)
|
||||
|
||||
wav_path = [f'~/.cache/modelscope/hub/{model_dir}/example/asr_example.wav']
|
||||
|
||||
result = model(wav_path)
|
||||
print(result)
|
||||
```
|
||||
|
||||
### 展開
|
||||
|
||||
未完了
|
||||
|
||||
## 微調整
|
||||
|
||||
### トレーニング環境のインストール
|
||||
|
||||
```shell
|
||||
git clone https://github.com/alibaba/FunASR.git && cd FunASR
|
||||
pip3 install -e ./
|
||||
```
|
||||
|
||||
### データ準備
|
||||
|
||||
データ形式には以下のフィールドが含まれている必要があります:
|
||||
```text
|
||||
{"key": "YOU0000008470_S0000238_punc_itn", "text_language": "<|en|>", "emo_target": "<|NEUTRAL|>", "event_target": "<|Speech|>", "with_or_wo_itn": "<|withitn|>", "target": "Including legal due diligence, subscription agreement, negotiation.", "source": "/cpfs01/shared/Group-speech/beinian.lzr/data/industrial_data/english_all/audio/YOU0000008470_S0000238.wav", "target_len": 7, "source_len": 140}
|
||||
{"key": "AUD0000001556_S0007580", "text_language": "<|en|>", "emo_target": "<|NEUTRAL|>", "event_target": "<|Speech|>", "with_or_wo_itn": "<|woitn|>", "target": "there is a tendency to identify the self or take interest in what one has got used to", "source": "/cpfs01/shared/Group-speech/beinian.lzr/data/industrial_data/english_all/audio/AUD0000001556_S0007580.wav", "target_len": 18, "source_len": 360}
|
||||
```
|
||||
詳細は:`data/train_example.jsonl`を参照してください。
|
||||
|
||||
### トレーニングの開始
|
||||
|
||||
`finetune.sh`の`train_tool`を、前述のFunASRパス内の`funasr/bin/train_ds.py`の絶対パスに変更することを忘れないでください。
|
||||
|
||||
```shell
|
||||
bash finetune.sh
|
||||
```
|
||||
|
||||
## WebUI
|
||||
|
||||
```shell
|
||||
python webui.py
|
||||
```
|
||||
|
||||
<div align="center"><img src="image/webui.png" width="700"/> </div>
|
||||
|
||||
# お問い合わせ
|
||||
|
||||
使用中に問題が発生した場合は、githubページで直接Issuesを提起できます。音声に興味のある方は、以下のDingTalkグループQRコードをスキャンしてコミュニティグループに参加し、交流と議論を行ってください。
|
||||
|
||||
| FunAudioLLM | FunASR |
|
||||
|:----------------------------------------------------------------:|:--------------------------------------------------------:|
|
||||
| <div align="left"><img src="image/dingding_sv.png" width="250"/> | <img src="image/dingding_funasr.png" width="250"/></div> |
|
||||
|
||||
102
README_zh.md
102
README_zh.md
@ -1,6 +1,6 @@
|
||||
# SenseVoice
|
||||
|
||||
「简体中文」|「[English](./README.md)」
|
||||
「简体中文」|「[English](./README.md)」|「[日本語](./README_ja.md)」
|
||||
|
||||
SenseVoice是具有音频理解能力的音频基础模型,包括语音识别(ASR)、语种识别(LID)、语音情感识别(SER)和声学事件分类(AEC)或声学事件检测(AED)。本项目提供SenseVoice模型的介绍以及在多个任务测试集上的benchmark,以及体验模型所需的环境安装的与推理方式。
|
||||
|
||||
@ -10,8 +10,7 @@ SenseVoice是具有音频理解能力的音频基础模型,包括语音识别
|
||||
[//]: # (<div align="center"><img src="image/sensevoice2.png" width="700"/> </div>)
|
||||
|
||||
<h4>
|
||||
<a href="https://www.modelscope.cn/studios/iic/SenseVoice"> 在线体验 </a>
|
||||
|<a href="#What's New"> 文档主页 </a>
|
||||
<a href="#What's New"> 文档主页 </a>
|
||||
|<a href="#核心功能"> 核心功能 </a>
|
||||
</h4>
|
||||
<h4>
|
||||
@ -22,7 +21,11 @@ SenseVoice是具有音频理解能力的音频基础模型,包括语音识别
|
||||
|<a href="#联系我们"> 联系我们 </a>
|
||||
</h4>
|
||||
|
||||
模型仓库:中国大陆用户推荐 [modelscope](https://www.modelscope.cn/models/iic/SenseVoiceSmall),海外用户推荐 [huggingface](https://huggingface.co/FunAudioLLM/SenseVoiceSmall)
|
||||
模型仓库:[modelscope](https://www.modelscope.cn/models/iic/SenseVoiceSmall),[huggingface](https://huggingface.co/FunAudioLLM/SenseVoiceSmall)
|
||||
|
||||
在线体验:
|
||||
[modelscope demo](https://www.modelscope.cn/studios/iic/SenseVoice), [huggingface space](https://huggingface.co/spaces/FunAudioLLM/SenseVoice)
|
||||
|
||||
</div>
|
||||
|
||||
<a name="核心功能"></a>
|
||||
@ -95,76 +98,97 @@ pip install -r requirements.txt
|
||||
|
||||
## 推理
|
||||
|
||||
### 直接推理
|
||||
|
||||
```python
|
||||
from model import SenseVoiceSmall
|
||||
|
||||
model_dir = "iic/SenseVoiceSmall"
|
||||
m, kwargs = SenseVoiceSmall.from_pretrained(model=model_dir)
|
||||
|
||||
|
||||
res = m.inference(
|
||||
data_in="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav",
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=False,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
print(res)
|
||||
```
|
||||
|
||||
### 使用funasr推理
|
||||
|
||||
支持任意格式音频输入,支持任意时长输入
|
||||
|
||||
```python
|
||||
from funasr import AutoModel
|
||||
from funasr.utils.postprocess_utils import rich_transcription_postprocess
|
||||
|
||||
model_dir = "iic/SenseVoiceSmall"
|
||||
input_file = (
|
||||
"https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav"
|
||||
|
||||
|
||||
model = AutoModel(
|
||||
model=model_dir,
|
||||
trust_remote_code=True,
|
||||
remote_code="./model.py",
|
||||
vad_model="fsmn-vad",
|
||||
vad_kwargs={"max_single_segment_time": 30000},
|
||||
device="cuda:0",
|
||||
)
|
||||
|
||||
model = AutoModel(model=model_dir,
|
||||
vad_model="fsmn-vad",
|
||||
vad_kwargs={"max_single_segment_time": 30000},
|
||||
trust_remote_code=True, device="cuda:0")
|
||||
|
||||
# en
|
||||
res = model.generate(
|
||||
input=input_file,
|
||||
input=f"{model.model_path}/example/en.mp3",
|
||||
cache={},
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=False,
|
||||
batch_size_s=0,
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=True,
|
||||
batch_size_s=60,
|
||||
merge_vad=True, #
|
||||
merge_length_s=15,
|
||||
)
|
||||
|
||||
text = rich_transcription_postprocess(res[0]["text"])
|
||||
|
||||
print(text)
|
||||
```
|
||||
参数说明:
|
||||
- `model_dir`:模型名称,或本地磁盘中的模型路径。
|
||||
- `trust_remote_code`:
|
||||
- `True`表示model代码实现从`remote_code`处加载,`remote_code`指定`model`具体代码的位置(例如,当前目录下的`model.py`),支持绝对路径与相对路径,以及网络url。
|
||||
- `False`表示,model代码实现为 [FunASR](https://github.com/modelscope/FunASR) 内部集成版本,此时修改当前目录下的`model.py`不会生效,因为加载的是funasr内部版本,模型代码[点击查看](https://github.com/modelscope/FunASR/tree/main/funasr/models/sense_voice)。
|
||||
- `vad_model`:表示开启VAD,VAD的作用是将长音频切割成短音频,此时推理耗时包括了VAD与SenseVoice总耗时,为链路耗时,如果需要单独测试SenseVoice模型耗时,可以关闭VAD模型。
|
||||
- `vad_kwargs`:表示VAD模型配置,`max_single_segment_time`: 表示`vad_model`最大切割音频时长, 单位是毫秒ms。
|
||||
- `use_itn`:输出结果中是否包含标点与逆文本正则化。
|
||||
- `batch_size_s` 表示采用动态batch,batch中总音频时长,单位为秒s。
|
||||
- `merge_vad`:是否将 vad 模型切割的短音频碎片合成,合并后长度为`merge_length_s`,单位为秒s。
|
||||
|
||||
funasr版本已经集成了vad模型,支持任意时长音频输入,`batch_size_s`单位为秒。
|
||||
如果输入均为短音频,并且需要批量化推理,为了加快推理效率,可以移除vad模型,并设置`batch_size`
|
||||
如果输入均为短音频(小于30s),并且需要批量化推理,为了加快推理效率,可以移除vad模型,并设置`batch_size`
|
||||
|
||||
```python
|
||||
model = AutoModel(model=model_dir, trust_remote_code=True, device="cuda:0")
|
||||
|
||||
res = model.generate(
|
||||
input=input_file,
|
||||
input=f"{model.model_path}/example/en.mp3",
|
||||
cache={},
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=False,
|
||||
use_itn=True,
|
||||
batch_size=64,
|
||||
)
|
||||
```
|
||||
|
||||
更多详细用法,请参考 [文档](https://github.com/modelscope/FunASR/blob/main/docs/tutorial/README.md)
|
||||
|
||||
### 直接推理
|
||||
|
||||
支持任意格式音频输入,输入音频时长限制在30s以下
|
||||
|
||||
```python
|
||||
from model import SenseVoiceSmall
|
||||
from funasr.utils.postprocess_utils import rich_transcription_postprocess
|
||||
|
||||
model_dir = "iic/SenseVoiceSmall"
|
||||
m, kwargs = SenseVoiceSmall.from_pretrained(model=model_dir, device="cuda:0")
|
||||
|
||||
|
||||
res = m.inference(
|
||||
data_in=f"{kwargs['model_path']}/example/en.mp3",
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=False,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
text = rich_transcription_postprocess(res[0][0]["text"])
|
||||
print(text)
|
||||
```
|
||||
|
||||
## 服务部署
|
||||
|
||||
Undo
|
||||
|
||||
### 导出与测试
|
||||
### 导出与测试(*进行中*)
|
||||
|
||||
|
||||
```python
|
||||
# pip3 install -U funasr-onnx
|
||||
|
||||
86
demo1.py
Normal file
86
demo1.py
Normal file
@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved.
|
||||
# MIT License (https://opensource.org/licenses/MIT)
|
||||
|
||||
|
||||
from funasr import AutoModel
|
||||
from funasr.utils.postprocess_utils import rich_transcription_postprocess
|
||||
|
||||
model_dir = "iic/SenseVoiceSmall"
|
||||
|
||||
|
||||
model = AutoModel(
|
||||
model=model_dir,
|
||||
trust_remote_code=True,
|
||||
remote_code="./model.py",
|
||||
vad_model="fsmn-vad",
|
||||
vad_kwargs={"max_single_segment_time": 30000},
|
||||
device="cuda:0",
|
||||
)
|
||||
|
||||
# en
|
||||
res = model.generate(
|
||||
input=f"{model.model_path}/example/en.mp3",
|
||||
cache={},
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=True,
|
||||
batch_size_s=60,
|
||||
merge_vad=True, #
|
||||
merge_length_s=15,
|
||||
)
|
||||
text = rich_transcription_postprocess(res[0]["text"])
|
||||
print(text)
|
||||
|
||||
# zh
|
||||
res = model.generate(
|
||||
input=f"{model.model_path}/example/zh.mp3",
|
||||
cache={},
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=True,
|
||||
batch_size_s=60,
|
||||
merge_vad=True, #
|
||||
merge_length_s=15,
|
||||
)
|
||||
text = rich_transcription_postprocess(res[0]["text"])
|
||||
print(text)
|
||||
|
||||
# yue
|
||||
res = model.generate(
|
||||
input=f"{model.model_path}/example/yue.mp3",
|
||||
cache={},
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=True,
|
||||
batch_size_s=60,
|
||||
merge_vad=True, #
|
||||
merge_length_s=15,
|
||||
)
|
||||
text = rich_transcription_postprocess(res[0]["text"])
|
||||
print(text)
|
||||
|
||||
# ja
|
||||
res = model.generate(
|
||||
input=f"{model.model_path}/example/ja.mp3",
|
||||
cache={},
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=True,
|
||||
batch_size_s=60,
|
||||
merge_vad=True, #
|
||||
merge_length_s=15,
|
||||
)
|
||||
text = rich_transcription_postprocess(res[0]["text"])
|
||||
print(text)
|
||||
|
||||
|
||||
# ko
|
||||
res = model.generate(
|
||||
input=f"{model.model_path}/example/ko.mp3",
|
||||
cache={},
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=True,
|
||||
batch_size_s=60,
|
||||
merge_vad=True, #
|
||||
merge_length_s=15,
|
||||
)
|
||||
text = rich_transcription_postprocess(res[0]["text"])
|
||||
print(text)
|
||||
@ -4,16 +4,19 @@
|
||||
# MIT License (https://opensource.org/licenses/MIT)
|
||||
|
||||
from model import SenseVoiceSmall
|
||||
from funasr.utils.postprocess_utils import rich_transcription_postprocess
|
||||
|
||||
|
||||
model_dir = "iic/SenseVoiceSmall"
|
||||
m, kwargs = SenseVoiceSmall.from_pretrained(model=model_dir)
|
||||
m, kwargs = SenseVoiceSmall.from_pretrained(model=model_dir, device="cuda:0")
|
||||
|
||||
|
||||
res = m.inference(
|
||||
data_in="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav",
|
||||
data_in=f"{kwargs['model_path']}/example/en.mp3",
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=False,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
print(res)
|
||||
text = rich_transcription_postprocess(res[0][0]["text"])
|
||||
print(text)
|
||||
@ -1,28 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved.
|
||||
# MIT License (https://opensource.org/licenses/MIT)
|
||||
|
||||
from funasr import AutoModel
|
||||
from funasr.utils.postprocess_utils import rich_transcription_postprocess
|
||||
|
||||
model_dir = "iic/SenseVoiceSmall"
|
||||
input_file = (
|
||||
"https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav"
|
||||
)
|
||||
|
||||
model = AutoModel(
|
||||
model=model_dir,
|
||||
trust_remote_code=True,
|
||||
)
|
||||
|
||||
res = model.generate(
|
||||
input=input_file,
|
||||
cache={},
|
||||
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=False,
|
||||
)
|
||||
|
||||
text = rich_transcription_postprocess(res[0]["text"])
|
||||
|
||||
print(text)
|
||||
@ -10,7 +10,7 @@ gpu_num=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}')
|
||||
# model_name from model_hub, or model_dir in local path
|
||||
|
||||
## option 1, download model automatically
|
||||
model_name_or_model_dir="iic/SenseVoiceCTC"
|
||||
model_name_or_model_dir="iic/SenseVoiceSmall"
|
||||
|
||||
## option 2, download model by git
|
||||
#local_path_root=${workspace}/modelscope_models
|
||||
|
||||
@ -3,5 +3,6 @@ torchaudio
|
||||
modelscope
|
||||
huggingface
|
||||
huggingface_hub
|
||||
funasr>=1.1.0
|
||||
numpy<=1.26.4
|
||||
funasr>=1.1.2
|
||||
numpy<=1.26.4
|
||||
gradio
|
||||
8
webui.py
8
webui.py
@ -168,7 +168,7 @@ def model_inference(input_wav, language, fs=16000):
|
||||
cache={},
|
||||
language=language,
|
||||
use_itn=True,
|
||||
batch_size_s=0, merge_vad=merge_vad)
|
||||
batch_size_s=60, merge_vad=merge_vad)
|
||||
|
||||
print(text)
|
||||
text = text[0]["text"]
|
||||
@ -203,7 +203,6 @@ audio_examples = [
|
||||
|
||||
|
||||
|
||||
|
||||
html_content = """
|
||||
<div>
|
||||
<h2 style="font-size: 22px;margin-left: 0px;">Voice Understanding Model: SenseVoice-Small</h2>
|
||||
@ -227,8 +226,6 @@ def launch():
|
||||
audio_inputs = gr.Audio(label="Upload audio or use the microphone")
|
||||
|
||||
with gr.Accordion("Configuration"):
|
||||
# task_inputs = gr.Radio(choices=["Speech Recognition", "Rich Text Transcription"],
|
||||
# value="Speech Recognition", label="Task")
|
||||
language_inputs = gr.Dropdown(choices=["auto", "zh", "en", "yue", "ja", "ko", "nospeech"],
|
||||
value="auto",
|
||||
label="Language")
|
||||
@ -237,8 +234,7 @@ def launch():
|
||||
gr.Examples(examples=audio_examples, inputs=[audio_inputs, language_inputs], examples_per_page=20)
|
||||
|
||||
fn_button.click(model_inference, inputs=[audio_inputs, language_inputs], outputs=text_outputs)
|
||||
# with gr.Accordion("More examples"):
|
||||
# gr.HTML(centered_table_html)
|
||||
|
||||
demo.launch()
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user