chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,236 @@
|
||||
# FAQ and Troubleshooting
|
||||
|
||||
This page collects the questions that most often block new FunASR users. Start here before opening an issue.
|
||||
|
||||
## Which install command should I use?
|
||||
|
||||
For most users:
|
||||
|
||||
```bash
|
||||
pip install -U funasr
|
||||
```
|
||||
|
||||
For the newest examples, server CLI, or unreleased fixes:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/modelscope/FunASR.git
|
||||
cd FunASR
|
||||
pip install -e ./
|
||||
```
|
||||
|
||||
For the OpenAI-compatible API server, install the web runtime dependencies too:
|
||||
|
||||
```bash
|
||||
pip install funasr fastapi uvicorn python-multipart
|
||||
```
|
||||
|
||||
## Which Python and PyTorch versions are recommended?
|
||||
|
||||
Use Python 3.8 or later and install a PyTorch/torchaudio pair that matches your CUDA runtime. If CUDA is not configured, start with CPU to verify the workflow first:
|
||||
|
||||
```bash
|
||||
funasr-server --model sensevoice --device cpu
|
||||
```
|
||||
|
||||
After the CPU smoke test works, switch to CUDA:
|
||||
|
||||
```bash
|
||||
funasr-server --model sensevoice --device cuda
|
||||
```
|
||||
|
||||
## Model download is slow or fails. What should I check?
|
||||
|
||||
FunASR models are available from ModelScope and Hugging Face. Choose the hub that is fastest in your network environment, and make sure the machine can reach it before debugging model code.
|
||||
|
||||
Common checks:
|
||||
|
||||
```bash
|
||||
python -c "import torch; print(torch.__version__, torch.cuda.is_available())"
|
||||
python -c "import funasr; print(funasr.__version__)"
|
||||
```
|
||||
|
||||
If a model is already downloaded on another machine, use the local model path instead of the remote model name.
|
||||
|
||||
## `funasr-server` says FastAPI or multipart packages are missing
|
||||
|
||||
Install the server dependencies:
|
||||
|
||||
```bash
|
||||
pip install fastapi uvicorn python-multipart
|
||||
```
|
||||
|
||||
Then start again:
|
||||
|
||||
```bash
|
||||
funasr-server --model sensevoice --device cuda
|
||||
```
|
||||
|
||||
## Port 8000 is already in use
|
||||
|
||||
Start the service on another port:
|
||||
|
||||
```bash
|
||||
funasr-server --model sensevoice --device cuda --port 9000
|
||||
```
|
||||
|
||||
Then point clients to the new base URL:
|
||||
|
||||
```bash
|
||||
curl http://localhost:9000/health
|
||||
```
|
||||
|
||||
## How do I verify the OpenAI-compatible API quickly?
|
||||
|
||||
Start the server:
|
||||
|
||||
```bash
|
||||
funasr-server --model sensevoice --device cuda
|
||||
```
|
||||
|
||||
In another terminal:
|
||||
|
||||
```bash
|
||||
curl -L https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/BAC009S0764W0121.wav -o sample.wav
|
||||
curl http://localhost:8000/v1/audio/transcriptions \
|
||||
-F file=@sample.wav \
|
||||
-F model=sensevoice \
|
||||
-F response_format=verbose_json
|
||||
```
|
||||
|
||||
The response should include `text`. With `verbose_json`, supported models may also return segment-level information.
|
||||
|
||||
## How do I run the OpenAI-compatible API with Docker Compose?
|
||||
|
||||
Use the example Compose setup when you want a reproducible local smoke test before wiring the API into a product or agent workflow:
|
||||
|
||||
```bash
|
||||
cd examples/openai_api
|
||||
cp .env.example .env
|
||||
docker compose up --build
|
||||
```
|
||||
|
||||
Then verify it from another terminal:
|
||||
|
||||
```bash
|
||||
BASE_URL=http://localhost:8000 bash smoke_test.sh
|
||||
```
|
||||
|
||||
The example container defaults to `FUNASR_DEVICE=cpu` so it can start on machines without NVIDIA Container Toolkit. For CUDA, first adapt the image to use CUDA-capable PyTorch/FunASR dependencies, then set `FUNASR_DEVICE=cuda`.
|
||||
|
||||
See also:
|
||||
|
||||
- [OpenAI API example](../../examples/openai_api/)
|
||||
- [Client recipes](../../examples/openai_api/CLIENTS.md)
|
||||
- [Deployment matrix](../deployment_matrix.md)
|
||||
|
||||
## Docker starts but `/health` or transcription fails
|
||||
|
||||
Check the container logs first:
|
||||
|
||||
```bash
|
||||
docker compose logs -f funasr-api
|
||||
```
|
||||
|
||||
Common causes:
|
||||
|
||||
- The first startup is still downloading or loading the model.
|
||||
- Port 8000 is already in use; set `FUNASR_HOST_PORT=9000` in `.env` and use `BASE_URL=http://localhost:9000`.
|
||||
- The container is running in CPU mode but `.env` or the command expects CUDA.
|
||||
- CUDA is requested but the image does not include CUDA-capable PyTorch/FunASR dependencies.
|
||||
- The model cache volume is empty or corrupted; retry after removing the `funasr-cache` Docker volume.
|
||||
- The uploaded audio file is too large for the machine; verify with the public sample before testing long recordings.
|
||||
|
||||
When opening a Deployment Help issue, include your `.env` values without secrets, the `docker compose` command, container logs, model alias, device, and audio duration.
|
||||
|
||||
## Long audio is slow, split incorrectly, or runs out of memory
|
||||
|
||||
Use VAD segmentation for long audio and tune segment length for your hardware:
|
||||
|
||||
```python
|
||||
from funasr import AutoModel
|
||||
|
||||
model = AutoModel(
|
||||
model="paraformer-zh",
|
||||
vad_model="fsmn-vad",
|
||||
punc_model="ct-punc",
|
||||
vad_kwargs={"max_single_segment_time": 30000},
|
||||
device="cuda",
|
||||
)
|
||||
result = model.generate(input="long_meeting.wav", batch_size_s=300)
|
||||
```
|
||||
|
||||
If memory is limited, reduce `batch_size_s`, use CPU for verification, or split very long recordings before batch processing.
|
||||
|
||||
## Speaker diarization has no speaker labels
|
||||
|
||||
Use a model pipeline that includes both VAD and speaker models:
|
||||
|
||||
```python
|
||||
from funasr import AutoModel
|
||||
|
||||
model = AutoModel(
|
||||
model="paraformer-zh",
|
||||
vad_model="fsmn-vad",
|
||||
punc_model="ct-punc",
|
||||
spk_model="cam++",
|
||||
device="cuda",
|
||||
)
|
||||
result = model.generate(input="meeting.wav")
|
||||
```
|
||||
|
||||
Then inspect `result[0]["sentence_info"]`. Each sentence should include fields such as `text`, `start`, `end`, and `spk` when diarization is available.
|
||||
|
||||
## Can I use a speaker model other than cam++?
|
||||
|
||||
Yes. `spk_model` can be any FunASR `AutoModel` speaker embedding model, including a ModelScope model ID or a local model path. For example, ERes2NetV2 can be used directly:
|
||||
|
||||
```python
|
||||
from funasr import AutoModel
|
||||
|
||||
model = AutoModel(
|
||||
model="paraformer-zh",
|
||||
vad_model="fsmn-vad",
|
||||
punc_model="ct-punc",
|
||||
spk_model="iic/speech_eres2netv2_sv_zh-cn_16k-common",
|
||||
device="cuda",
|
||||
)
|
||||
result = model.generate(input="meeting.wav")
|
||||
```
|
||||
|
||||
For a fully custom speaker model, make sure the model can be loaded by FunASR `AutoModel` and that its `inference()` method returns `spk_embedding`; the user-facing call still goes through `AutoModel.generate()`. The diarization post-processing and clustering steps use those embeddings to assign speaker labels. If your diarization model emits speaker segments directly instead of embeddings, add an adapter layer that converts its output to the current speaker-label structure.
|
||||
|
||||
The tutorial has a longer ERes2NetV2 example: [Speaker Verification / Diarization](../tutorial/README.md#speaker-verification--diarization-eres2netv2).
|
||||
|
||||
## The same command works on CPU but fails on CUDA
|
||||
|
||||
This usually points to a CUDA, driver, PyTorch, or GPU memory mismatch. Include these checks in your issue:
|
||||
|
||||
```bash
|
||||
nvidia-smi
|
||||
python -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available())"
|
||||
python -c "import torchaudio; print(torchaudio.__version__)"
|
||||
```
|
||||
|
||||
Try a smaller model or lower batch size to rule out GPU memory pressure.
|
||||
|
||||
## What information should I include in an issue?
|
||||
|
||||
Please include:
|
||||
|
||||
- OS and Python version
|
||||
- FunASR version and install method (`pip`, source, Docker)
|
||||
- PyTorch, torchaudio, CUDA, and GPU information
|
||||
- Exact command or minimal Python snippet
|
||||
- Full traceback or server logs
|
||||
- Model name and hub (`modelscope`, `hf`, or local path)
|
||||
- Audio duration, sample rate, format, language, speaker count, and whether the audio can be shared
|
||||
|
||||
## Existing ModelScope pipeline examples
|
||||
|
||||
- [VAD model with ModelScope pipeline](https://github.com/modelscope/FunASR/discussions/236)
|
||||
- [Punctuation model with ModelScope pipeline](https://github.com/modelscope/FunASR/discussions/238)
|
||||
- [Paraformer streaming with ModelScope pipeline](https://github.com/modelscope/FunASR/discussions/241)
|
||||
- [VAD + ASR + punctuation with ModelScope pipeline](https://github.com/modelscope/FunASR/discussions/278)
|
||||
- [VAD + ASR + punctuation + NNLM with ModelScope pipeline](https://github.com/modelscope/FunASR/discussions/134)
|
||||
- [Timestamp prediction with ModelScope pipeline](https://github.com/modelscope/FunASR/discussions/246)
|
||||
- [Switch online/offline decoding for UniASR](https://github.com/modelscope/FunASR/discussions/151)
|
||||
@@ -0,0 +1,5 @@
|
||||
## Audio Cut
|
||||
|
||||
## Realtime Speech Recognition
|
||||
|
||||
## Audio Chat
|
||||
@@ -0,0 +1,125 @@
|
||||
# Build custom tasks
|
||||
FunASR is similar to ESPNet, which applies `Task` as the general interface ti achieve the training and inference of models. Each `Task` is a class inherited from `AbsTask` and its corresponding code can be seen in `funasr/tasks/abs_task.py`. The main functions of `AbsTask` are shown as follows:
|
||||
```python
|
||||
class AbsTask(ABC):
|
||||
@classmethod
|
||||
def add_task_arguments(cls, parser: argparse.ArgumentParser):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def build_preprocess_fn(cls, args, train):
|
||||
(...)
|
||||
|
||||
@classmethod
|
||||
def build_collate_fn(cls, args: argparse.Namespace):
|
||||
(...)
|
||||
|
||||
@classmethod
|
||||
def build_model(cls, args):
|
||||
(...)
|
||||
|
||||
@classmethod
|
||||
def main(cls, args):
|
||||
(...)
|
||||
```
|
||||
- add_task_arguments:Add parameters required by a specified `Task`
|
||||
- build_preprocess_fn:定义如何处理对样本进行预处理 define how to preprocess samples
|
||||
- build_collate_fn:define how to combine multiple samples into a `batch`
|
||||
- build_model:define the model
|
||||
- main:training interface, starting training through `Task.main()`
|
||||
|
||||
Next, we take the speech recognition as an example to introduce how to define a new `Task`. For the corresponding code, please see `ASRTask` in `funasr/tasks/asr.py`. The procedure of defining a new `Task` is actually the procedure of redefining the above functions according to the requirements of the specified `Task`.
|
||||
|
||||
- add_task_arguments
|
||||
```python
|
||||
@classmethod
|
||||
def add_task_arguments(cls, parser: argparse.ArgumentParser):
|
||||
group = parser.add_argument_group(description="Task related")
|
||||
group.add_argument(
|
||||
"--token_list",
|
||||
type=str_or_none,
|
||||
default=None,
|
||||
help="A text mapping int-id to token",
|
||||
)
|
||||
(...)
|
||||
```
|
||||
For speech recognition tasks, specific parameters required include `token_list`, etc. According to the specific requirements of different tasks, users can define corresponding parameters in this function.
|
||||
|
||||
- build_preprocess_fn
|
||||
```python
|
||||
@classmethod
|
||||
def build_preprocess_fn(cls, args, train):
|
||||
if args.use_preprocessor:
|
||||
retval = CommonPreprocessor(
|
||||
train=train,
|
||||
token_type=args.token_type,
|
||||
token_list=args.token_list,
|
||||
bpemodel=args.bpemodel,
|
||||
non_linguistic_symbols=args.non_linguistic_symbols,
|
||||
text_cleaner=args.cleaner,
|
||||
...
|
||||
)
|
||||
else:
|
||||
retval = None
|
||||
return retval
|
||||
```
|
||||
This function defines how to preprocess samples. Specifically, the input of speech recognition tasks includes speech and text. For speech, functions such as (optional) adding noise and reverberation to the speech are supported. For text, functions such as (optional) processing text according to bpe and mapping text to `tokenid` are supported. Users can choose the preprocessing operation that needs to be performed on the sample. For the detail implementation, please refer to `CommonPreprocessor`.
|
||||
|
||||
- build_collate_fn
|
||||
```python
|
||||
@classmethod
|
||||
def build_collate_fn(cls, args, train):
|
||||
return CommonCollateFn(float_pad_value=0.0, int_pad_value=-1)
|
||||
```
|
||||
This function defines how to combine multiple samples into a `batch`. For speech recognition tasks, `padding` is employed to obtain equal-length data from different speech and text. Specifically, we set `0.0` as the default padding value for speech and `-1` as the default padding value for text. Users can define different `batch` operations here. For the detail implementation, please refer to `CommonCollateFn`.
|
||||
|
||||
- build_model
|
||||
```python
|
||||
@classmethod
|
||||
def build_model(cls, args, train):
|
||||
with open(args.token_list, encoding="utf-8") as f:
|
||||
token_list = [line.rstrip() for line in f]
|
||||
vocab_size = len(token_list)
|
||||
frontend = frontend_class(**args.frontend_conf)
|
||||
specaug = specaug_class(**args.specaug_conf)
|
||||
normalize = normalize_class(**args.normalize_conf)
|
||||
preencoder = preencoder_class(**args.preencoder_conf)
|
||||
encoder = encoder_class(input_size=input_size, **args.encoder_conf)
|
||||
postencoder = postencoder_class(input_size=encoder_output_size, **args.postencoder_conf)
|
||||
decoder = decoder_class(vocab_size=vocab_size, encoder_output_size=encoder_output_size, **args.decoder_conf)
|
||||
ctc = CTC(odim=vocab_size, encoder_output_size=encoder_output_size, **args.ctc_conf)
|
||||
model = model_class(
|
||||
vocab_size=vocab_size,
|
||||
frontend=frontend,
|
||||
specaug=specaug,
|
||||
normalize=normalize,
|
||||
preencoder=preencoder,
|
||||
encoder=encoder,
|
||||
postencoder=postencoder,
|
||||
decoder=decoder,
|
||||
ctc=ctc,
|
||||
token_list=token_list,
|
||||
**args.model_conf,
|
||||
)
|
||||
return model
|
||||
```
|
||||
This function defines the detail of the model. For different speech recognition models, the same speech recognition `Task` can usually be shared and the remaining thing needed to be done is to define a specific model in this function. For example, a speech recognition model with a standard encoder-decoder structure has been shown above. Specifically, it first defines each module of the model, including encoder, decoder, etc. and then combine these modules together to generate a complete model. In FunASR, the model needs to inherit `FunASRModel` and the corresponding code can be seen in `funasr/train/abs_espnet_model.py`. The main function needed to be implemented is the `forward` function.
|
||||
|
||||
Next, we take `SANMEncoder` as an example to introduce how to use a custom encoder as a part of the model when defining the specified model and the corresponding code can be seen in `funasr/models/encoder/sanm_encoder.py`. For a custom encoder, in addition to inheriting the common encoder class `AbsEncoder`, it is also necessary to define the `forward` function to achieve the forward computation of the `encoder`. After defining the `encoder`, it should also be registered in the `Task`. The corresponding code example can be seen as below:
|
||||
```python
|
||||
encoder_choices = ClassChoices(
|
||||
"encoder",
|
||||
classes=dict(
|
||||
conformer=ConformerEncoder,
|
||||
transformer=TransformerEncoder,
|
||||
rnn=RNNEncoder,
|
||||
sanm=SANMEncoder,
|
||||
sanm_chunk_opt=SANMEncoderChunkOpt,
|
||||
data2vec_encoder=Data2VecEncoder,
|
||||
mfcca_enc=MFCCAEncoder,
|
||||
),
|
||||
type_check=AbsEncoder,
|
||||
default="rnn",
|
||||
)
|
||||
```
|
||||
In this code, `sanm=SANMEncoder` takes the newly defined `SANMEncoder` as an optional choice of the `encoder`. Once the user specifies the `encoder` as `sanm` in the configuration file, the `SANMEncoder` will be correspondingly employed as the `encoder` module of the model.
|
||||
@@ -0,0 +1,38 @@
|
||||
# Papers
|
||||
|
||||
FunASR have implemented the following paper code
|
||||
|
||||
### Speech Recognition
|
||||
- [FunASR: A Fundamental End-to-End Speech Recognition Toolkit](https://arxiv.org/abs/2305.11013), INTERSPEECH 2023
|
||||
- [BAT: Boundary aware transducer for memory-efficient and low-latency ASR](https://arxiv.org/abs/2305.11571), INTERSPEECH 2023
|
||||
- [Paraformer: Fast and Accurate Parallel Transformer for Non-autoregressive End-to-End Speech Recognition](https://arxiv.org/abs/2206.08317), INTERSPEECH 2022
|
||||
- [E-branchformer: Branchformer with enhanced merging for speech recognition](https://arxiv.org/abs/2210.00077), SLT 2022
|
||||
- [Branchformer: Parallel mlp-attention architectures to capture local and global context for speech recognition and understanding](https://proceedings.mlr.press/v162/peng22a.html?ref=https://githubhelp.com), ICML 2022
|
||||
- [Universal ASR: Unifying Streaming and Non-Streaming ASR Using a Single Encoder-Decoder Model](https://arxiv.org/abs/2010.14099), arXiv preprint arXiv:2010.14099, 2020
|
||||
- [San-m: Memory equipped self-attention for end-to-end speech recognition](https://arxiv.org/pdf/2006.01713), INTERSPEECH 2020
|
||||
- [Streaming Chunk-Aware Multihead Attention for Online End-to-End Speech Recognition](https://arxiv.org/abs/2006.01712), INTERSPEECH 2020
|
||||
- [Conformer: Convolution-augmented Transformer for Speech Recognition](https://arxiv.org/abs/2005.08100), INTERSPEECH 2020
|
||||
- [Sequence-to-sequence learning with Transducers](https://arxiv.org/pdf/1211.3711.pdf), NIPS 2016
|
||||
|
||||
|
||||
### Multi-talker Speech Recognition
|
||||
- [MFCCA:Multi-Frame Cross-Channel attention for multi-speaker ASR in Multi-party meeting scenario](https://arxiv.org/abs/2210.05265), ICASSP 2022
|
||||
|
||||
### Voice Activity Detection
|
||||
- [Deep-FSMN for Large Vocabulary Continuous Speech Recognition](https://arxiv.org/abs/1803.05030), ICASSP 2018
|
||||
|
||||
### Punctuation Restoration
|
||||
- [CT-Transformer: Controllable time-delay transformer for real-time punctuation prediction and disfluency detection](https://arxiv.org/pdf/2003.01309.pdf), ICASSP 2018
|
||||
|
||||
### Language Models
|
||||
- [Attention Is All You Need](https://arxiv.org/abs/1706.03762), NEURIPS 2017
|
||||
|
||||
### Speaker Verification
|
||||
- [X-VECTORS: ROBUST DNN EMBEDDINGS FOR SPEAKER RECOGNITION](https://www.danielpovey.com/files/2018_icassp_xvectors.pdf), ICASSP 2018
|
||||
|
||||
### Speaker diarization
|
||||
- [Speaker Overlap-aware Neural Diarization for Multi-party Meeting Analysis](https://arxiv.org/abs/2211.10243), EMNLP 2022
|
||||
- [TOLD: A Novel Two-Stage Overlap-Aware Framework for Speaker Diarization](https://arxiv.org/abs/2303.05397), ICASSP 2023
|
||||
|
||||
### Timestamp Prediction
|
||||
- [Achieving Timestamp Prediction While Recognizing with Non-Autoregressive End-to-End ASR Model](https://arxiv.org/abs/2301.12343), arXiv:2301.12343
|
||||
Reference in New Issue
Block a user