Automatic Speech Recognition
Transformers
Safetensors
English
asr_model
asr
speech-recognition
speech-to-text
audio
speech-llm
word-timestamps
speaker-diarization
qwen
granite-speech
lora
custom_code
Eval Results (legacy)
Instructions to use mazesmazes/tiny-audio with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mazesmazes/tiny-audio with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("automatic-speech-recognition", model="mazesmazes/tiny-audio", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForSpeechSeq2Seq model = AutoModelForSpeechSeq2Seq.from_pretrained("mazesmazes/tiny-audio", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update custom model files, README, and requirements
Browse files- asr_pipeline.py +32 -2
asr_pipeline.py
CHANGED
|
@@ -29,7 +29,7 @@ __all__ = [
|
|
| 29 |
"SpeakerDiarizer",
|
| 30 |
]
|
| 31 |
|
| 32 |
-
#
|
| 33 |
# these lengths. The model trained on clips of at most 19 s; 18 leaves room for
|
| 34 |
# the inference lead-in. Short clips are one chunk, so their text is unchanged.
|
| 35 |
CHUNK_MAX_S = 18.0
|
|
@@ -144,7 +144,7 @@ class ASRPipeline(transformers.AutomaticSpeechRecognitionPipeline):
|
|
| 144 |
|
| 145 |
try:
|
| 146 |
if not return_timestamps:
|
| 147 |
-
return
|
| 148 |
return self._transcribe_timed(
|
| 149 |
inputs,
|
| 150 |
return_speakers=return_speakers,
|
|
@@ -155,6 +155,36 @@ class ASRPipeline(transformers.AutomaticSpeechRecognitionPipeline):
|
|
| 155 |
if original_prompt is not None:
|
| 156 |
self.model.TRANSCRIBE_PROMPT = original_prompt
|
| 157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
def _transcribe_timed(
|
| 159 |
self,
|
| 160 |
inputs,
|
|
|
|
| 29 |
"SpeakerDiarizer",
|
| 30 |
]
|
| 31 |
|
| 32 |
+
# Audio is transcribed in chunks cut at the quietest point between
|
| 33 |
# these lengths. The model trained on clips of at most 19 s; 18 leaves room for
|
| 34 |
# the inference lead-in. Short clips are one chunk, so their text is unchanged.
|
| 35 |
CHUNK_MAX_S = 18.0
|
|
|
|
| 144 |
|
| 145 |
try:
|
| 146 |
if not return_timestamps:
|
| 147 |
+
return self._transcribe_plain(inputs, **kwargs)
|
| 148 |
return self._transcribe_timed(
|
| 149 |
inputs,
|
| 150 |
return_speakers=return_speakers,
|
|
|
|
| 155 |
if original_prompt is not None:
|
| 156 |
self.model.TRANSCRIBE_PROMPT = original_prompt
|
| 157 |
|
| 158 |
+
def _transcribe_plain(self, inputs, **kwargs):
|
| 159 |
+
"""Transcribe in the same chunks as `_transcribe_timed`, without timing words.
|
| 160 |
+
|
| 161 |
+
One call over a whole recording returns only its first
|
| 162 |
+
`max_new_tokens` of text (WER 97% on a 30-min AMI meeting), so plain
|
| 163 |
+
transcription chunks too. A short clip is one chunk: one call, the
|
| 164 |
+
same result as before. Inputs `_extract_audio` can't read (a batch)
|
| 165 |
+
go to the parent untouched.
|
| 166 |
+
"""
|
| 167 |
+
audio = self._extract_audio(inputs)
|
| 168 |
+
if audio is None:
|
| 169 |
+
return super().__call__(inputs, **kwargs)
|
| 170 |
+
array = np.asarray(audio["array"], dtype=np.float32)
|
| 171 |
+
sr = audio.get("sampling_rate", 16000)
|
| 172 |
+
|
| 173 |
+
bounds = chunk_bounds(array, sr)
|
| 174 |
+
if len(bounds) == 1:
|
| 175 |
+
return super().__call__({"raw": array, "sampling_rate": sr}, **kwargs)
|
| 176 |
+
result: dict[str, Any] = {}
|
| 177 |
+
texts = []
|
| 178 |
+
for s, e in bounds:
|
| 179 |
+
out = super().__call__({"raw": array[s:e], "sampling_rate": sr}, **kwargs)
|
| 180 |
+
texts.append(out["text"])
|
| 181 |
+
# Per-step logprobs (output_scores=True) run on across chunks.
|
| 182 |
+
for key in ("top1_logprob", "top2_logprob"):
|
| 183 |
+
if key in out:
|
| 184 |
+
result.setdefault(key, []).extend(out[key])
|
| 185 |
+
result["text"] = " ".join(t for t in texts if t)
|
| 186 |
+
return result
|
| 187 |
+
|
| 188 |
def _transcribe_timed(
|
| 189 |
self,
|
| 190 |
inputs,
|