Spaces:
Paused
Paused
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,29 +1,62 @@
|
|
| 1 |
---
|
| 2 |
-
title: Live Whisper Speech To Text
|
| 3 |
emoji: ποΈ
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
# Live Speech-to-Text
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
## How it works
|
| 19 |
|
| 20 |
-
- The browser streams
|
| 21 |
-
|
| 22 |
-
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
## Run locally
|
| 29 |
|
|
@@ -32,9 +65,23 @@ pip install -r requirements.txt
|
|
| 32 |
python app.py
|
| 33 |
```
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Live Whisper MLX Speech To Text
|
| 3 |
emoji: ποΈ
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 6.26.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
suggested_hardware: cpu-basic
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# Live Speech-to-Text β Whisper on MLX
|
| 14 |
|
| 15 |
+
Real-time transcription with `openai/whisper-tiny.en` running on
|
| 16 |
+
[MLX](https://github.com/ml-explore/mlx). **No PyTorch anywhere in the
|
| 17 |
+
dependency tree** β 35 packages installed, none of them torch.
|
| 18 |
+
|
| 19 |
+
Built for Apple Silicon, where MLX uses Metal. It still builds and runs
|
| 20 |
+
on Hugging Face's free Linux CPU tier via `mlx[cpu]`.
|
| 21 |
|
| 22 |
## How it works
|
| 23 |
|
| 24 |
+
- The browser streams microphone chunks via `gr.Audio(streaming=True)`.
|
| 25 |
+
- Each chunk is converted to mono, resampled to 16 kHz with an
|
| 26 |
+
anti-aliased polyphase filter, and turned into a mel spectrogram.
|
| 27 |
+
- A per-session **AlignAtt streaming decoder** consumes each chunk and
|
| 28 |
+
emits only the tokens its cross-attention says have settled.
|
| 29 |
+
|
| 30 |
+
### Why streaming, not a rolling buffer
|
| 31 |
+
|
| 32 |
+
The obvious approach β keep the last N seconds of audio and re-run
|
| 33 |
+
`model.generate()` on it every chunk β costs more as the buffer grows,
|
| 34 |
+
and hallucinates. Measured on one 2.8s clip of real speech:
|
| 35 |
+
|
| 36 |
+
| approach | output |
|
| 37 |
+
|---|---|
|
| 38 |
+
| `generate()` on the buffer | `The quick brown fox jumps over the lazy dog. The The The The The Theβ¦` |
|
| 39 |
+
| streaming decoder | `the` β `quick brown fox` β `jumps over` β `the lazy dog.` |
|
| 40 |
+
|
| 41 |
+
Whisper pads its input to 30 seconds internally and keeps decoding into
|
| 42 |
+
that padding, so the filler is structural rather than bad luck β it
|
| 43 |
+
survived greedy decoding, disabling `condition_on_previous_text`, and
|
| 44 |
+
trimming trailing silence. The streaming decoder never has the problem
|
| 45 |
+
because it only emits what the audio actually supports.
|
| 46 |
+
|
| 47 |
+
Throughput on an M-series Mac: roughly **8Γ realtime** for `tiny.en`.
|
| 48 |
+
|
| 49 |
+
## Hardware
|
| 50 |
+
|
| 51 |
+
Designed for **`cpu-basic`**. Requesting a GPU tier has a cost beyond the
|
| 52 |
+
bill: a Space set to ZeroGPU (`zero-a10g`) can only run on Hugging Face's
|
| 53 |
+
infrastructure, because ZeroGPU apps are expected to import the `spaces`
|
| 54 |
+
package and decorate their entrypoints β which makes the Space
|
| 55 |
+
unrunnable anywhere else, including on your own machine.
|
| 56 |
+
|
| 57 |
+
`suggested_hardware` above only advises people who *duplicate* this
|
| 58 |
+
Space. The tier this Space actually runs on is a repository setting β
|
| 59 |
+
**Settings β Hardware** in the Space UI β and must be changed there.
|
| 60 |
|
| 61 |
## Run locally
|
| 62 |
|
|
|
|
| 65 |
python app.py
|
| 66 |
```
|
| 67 |
|
| 68 |
+
Or through [sidepage](https://github.com/kalpi-4/sidepage), which fetches
|
| 69 |
+
the Space, shows you the plan, and asks before running anything:
|
| 70 |
+
|
| 71 |
+
```bash
|
| 72 |
+
sidepage pull huggingface.co/spaces/<owner>/<name>
|
| 73 |
+
sidepage serve <name> # prompts for confirmation, then serves
|
| 74 |
+
sidepage serve <name> --anon # ...and gives you a public URL
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
## Tuning
|
| 78 |
+
|
| 79 |
+
| Variable | Default | What it does |
|
| 80 |
+
|---|---|---|
|
| 81 |
+
| `WHISPER_MODEL` | `openai/whisper-tiny.en` | `openai/whisper-base.en` is more accurate and slower; `openai/whisper-small.en` more so |
|
| 82 |
+
| `WHISPER_STREAM_EVERY` | `0.75` | Seconds between chunks β lower is more responsive, and more CPU |
|
| 83 |
|
| 84 |
+
Use the standard `openai/*` repos, not the pre-converted
|
| 85 |
+
`mlx-community/whisper-*-mlx` ones: mlx-audio converts the weights itself
|
| 86 |
+
on load and needs the Hugging Face processor files, which those repos
|
| 87 |
+
don't ship. Loading one fails with *"Processor not found."*
|