Views
No views yet
| Release | Test WER | GPUs |
|---|---|---|
| 2024-11-08 | 11.00% | 4xA100 40GB |
| full | cs=32 (1280ms) | 24 (960ms) | 16 (640ms) | 12 (480ms) | 8 (320ms) | |
|---|---|---|---|---|---|---|
| full | 11.00% | - | - | - | - | - |
| 16 | - | - | - | 11.70% | 11.84% | 12.14% |
| 8 | - | - | 11.50% | 11.72% | 11.88% | 12.28% |
| 4 | - | 11.40% | 11.53% | 11.81% | 12.03% | 12.64% |
| 2 | - | 11.46% | 11.67% | 12.03% | 12.43% | 13.25% |
| 1* | - | 11.59% | 11.85% | 12.39% | 12.93% | 14.13% |
transcribe_file if needed.pip install speechbrain1from speechbrain.inference.ASR import StreamingASR
2from speechbrain.utils.dynamic_chunk_training import DynChunkTrainConfig
3asr_model = StreamingASR.from_hparams("speechbrain/asr-streaming-conformer-gigaspeech")
4asr_model.transcribe_file(
5 "speechbrain/asr-streaming-conformer-librispeech/test-en.wav",
6 # select a chunk size of ~960ms with 4 chunks of left context
7 DynChunkTrainConfig(24, 4),
8 # disable torchaudio streaming to allow fetching from HuggingFace
9 # set this to True for your own files or streams to allow for streaming file decoding
10 use_torchaudio_streaming=False,
11)DynChunkTrainConfig values can be adjusted for a tradeoff of latency, computational power and transcription accuracy. Refer to the streaming WER table to pick a value that is suitable for your usecase.python3 asr.py http://as-hls-ww-live.akamaized.net/pool_904/live/ww/bbc_radio_fourfm/bbc_radio_fourfm.isml/bbc_radio_fourfm-audio%3d96000.norewind.m3u8 --model-source=speechbrain/asr-streaming-conformer-gigaspeech --device=cpu -vpython3 asr.py some-english-speech.wav --model-source=speechbrain/asr-streaming-conformer-gigaspeech --device=cpu -v1from argparse import ArgumentParser
2import logging
3
4parser = ArgumentParser()
5parser.add_argument("audio_path")
6parser.add_argument("--model-source", required=True)
7parser.add_argument("--device", default="cpu")
8parser.add_argument("--ip", default="127.0.0.1")
9parser.add_argument("--port", default=9431)
10parser.add_argument("--chunk-size", default=24, type=int)
11parser.add_argument("--left-context-chunks", default=4, type=int)
12parser.add_argument("--num-threads", default=None, type=int)
13parser.add_argument("--verbose", "-v", default=False, action="store_true")
14args = parser.parse_args()
15
16if args.verbose:
17 logging.getLogger().setLevel(logging.INFO)
18
19logging.info("Loading libraries")
20
21from speechbrain.inference.ASR import StreamingASR
22from speechbrain.utils.dynamic_chunk_training import DynChunkTrainConfig
23import torch
24
25device = args.device
26
27if args.num_threads is not None:
28 torch.set_num_threads(args.num_threads)
29
30logging.info(f"Loading model from \"{args.model_source}\" onto device {device}")
31
32asr = StreamingASR.from_hparams(args.model_source, run_opts={"device": device})
33config = DynChunkTrainConfig(args.chunk_size, args.left_context_chunks)
34
35logging.info(f"Starting stream from URI \"{args.audio_path}\"")
36
37for text_chunk in asr.transcribe_file_streaming(args.audio_path, config):
38 print(text_chunk, flush=True, end="")python3 gradio-asr.py --model-source speechbrain/asr-streaming-conformer-gigaspeech --ip=localhost --device=cpu1from argparse import ArgumentParser
2from dataclasses import dataclass
3import logging
4
5parser = ArgumentParser()
6parser.add_argument("--model-source", required=True)
7parser.add_argument("--device", default="cpu")
8parser.add_argument("--ip", default="127.0.0.1")
9parser.add_argument("--port", default=9431)
10parser.add_argument("--chunk-size", default=24, type=int)
11parser.add_argument("--left-context-chunks", default=4, type=int)
12parser.add_argument("--num-threads", default=None, type=int)
13parser.add_argument("--verbose", "-v", default=False, action="store_true")
14args = parser.parse_args()
15
16if args.verbose:
17 logging.getLogger().setLevel(logging.INFO)
18
19logging.info("Loading libraries")
20
21from speechbrain.inference.ASR import StreamingASR, ASRStreamingContext
22from speechbrain.utils.dynamic_chunk_training import DynChunkTrainConfig
23import torch
24import gradio as gr
25import torchaudio
26import numpy as np
27
28device = args.device
29
30if args.num_threads is not None:
31 torch.set_num_threads(args.num_threads)
32
33logging.info(f"Loading model from \"{args.model_source}\" onto device {device}")
34
35asr = StreamingASR.from_hparams(args.model_source, run_opts={"device": device})
36config = DynChunkTrainConfig(args.chunk_size, args.left_context_chunks)
37
38@dataclass
39class GradioStreamingContext:
40 context: ASRStreamingContext
41 chunk_size: int
42 waveform_buffer: torch.Tensor
43 decoded_text: str
44
45def transcribe(stream, new_chunk):
46 sr, y = new_chunk
47
48 y = y.astype(np.float32)
49 y = torch.tensor(y, dtype=torch.float32, device=device)
50 y /= max(1, torch.max(torch.abs(y)).item()) # norm by max abs() within chunk & avoid NaN
51 if len(y.shape) > 1:
52 y = torch.mean(y, dim=1) # downmix to mono
53
54 # HACK: we are making poor use of the resampler across chunk boundaries
55 # which may degrade accuracy.
56 # NOTE: we should also absolutely avoid recreating a resampler every time
57 resampler = torchaudio.transforms.Resample(orig_freq=sr, new_freq=asr.audio_normalizer.sample_rate).to(device)
58 y = resampler(y) # janky resample (probably to 16kHz)
59
60
61 if stream is None:
62 stream = GradioStreamingContext(
63 context=asr.make_streaming_context(config),
64 chunk_size=asr.get_chunk_size_frames(config),
65 waveform_buffer=y,
66 decoded_text="",
67 )
68 else:
69 stream.waveform_buffer = torch.concat((stream.waveform_buffer, y))
70
71 while stream.waveform_buffer.size(0) > stream.chunk_size:
72 chunk = stream.waveform_buffer[:stream.chunk_size]
73 stream.waveform_buffer = stream.waveform_buffer[stream.chunk_size:]
74
75 # fake batch dim
76 chunk = chunk.unsqueeze(0)
77
78 # list of transcribed strings, of size 1 because the batch size is 1
79 with torch.no_grad():
80 transcribed = asr.transcribe_chunk(stream.context, chunk)
81 stream.decoded_text += transcribed[0]
82
83 return stream, stream.decoded_text
84
85# NOTE: latency seems relatively high, which may be due to this:
86# https://github.com/gradio-app/gradio/issues/6526
87
88demo = gr.Interface(
89 transcribe,
90 ["state", gr.Audio(sources=["microphone"], streaming=True)],
91 ["state", "text"],
92 live=True,
93)
94
95demo.launch(server_name=args.ip, server_port=args.port)run_opts={"device":"cuda"} when calling the from_hparams method.encode_chunk) do.v1.0.2.
To train it from scratch, follow these steps:git clone https://github.com/speechbrain/speechbrain/1cd speechbrain
2pip install -r requirements.txt
3pip install -e .1@misc{speechbrainV1,
2 title={Open-Source Conversational AI with SpeechBrain 1.0},
3 author={Mirco Ravanelli and Titouan Parcollet and Adel Moumen and Sylvain de Langen and Cem Subakan and Peter Plantinga and Yingzhi Wang and Pooneh Mousavi and Luca Della Libera and Artem Ploujnikov and Francesco Paissan and Davide Borra and Salah Zaiem and Zeyu Zhao and Shucong Zhang and Georgios Karakasidis and Sung-Lin Yeh and Pierre Champion and Aku Rouhe and Rudolf Braun and Florian Mai and Juan Zuluaga-Gomez and Seyed Mahed Mousavi and Andreas Nautsch and Xuechen Liu and Sangeet Sagar and Jarod Duret and Salima Mdhaffar and Gaelle Laperriere and Mickael Rouvier and Renato De Mori and Yannick Esteve},
4 year={2024},
5 eprint={2407.00463},
6 archivePrefix={arXiv},
7 primaryClass={cs.LG},
8 url={https://arxiv.org/abs/2407.00463},
9}
10@misc{speechbrain,
11 title={{SpeechBrain}: A General-Purpose Speech Toolkit},
12 author={Mirco Ravanelli and Titouan Parcollet and Peter Plantinga and Aku Rouhe and Samuele Cornell and Loren Lugosch and Cem Subakan and Nauman Dawalatabad and Abdelwahab Heba and Jianyuan Zhong and Ju-Chieh Chou and Sung-Lin Yeh and Szu-Wei Fu and Chien-Feng Liao and Elena Rastorgueva and François Grondin and William Aris and Hwidong Na and Yan Gao and Renato De Mori and Yoshua Bengio},
13 year={2021},
14 eprint={2106.04624},
15 archivePrefix={arXiv},
16 primaryClass={eess.AS},
17 note={arXiv:2106.04624}
18}