Spaces:
Paused

kalpi314 commited on
Commit
3c40194
·
verified ·
1 Parent(s): 1fa72d8

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +34 -9
  2. app.py +82 -0
  3. requirements.txt +4 -0
README.md CHANGED
@@ -1,15 +1,40 @@
1
  ---
2
- title: Tiny Notes
3
- emoji: 📊
4
- colorFrom: indigo
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 6.26.0
8
- python_version: '3.12'
9
  app_file: app.py
10
  pinned: false
11
- license: apache-2.0
12
- short_description: small tts notetaker
13
  ---
14
 
15
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Live Whisper Speech To Text
3
+ emoji: 🎙️
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 4.44.0
 
8
  app_file: app.py
9
  pinned: false
 
 
10
  ---
11
 
12
+ # Live Speech-to-Text (Whisper tiny.en)
13
+
14
+ A minimal, real-time speech-to-text demo built with Gradio and a small
15
+ Whisper model (`openai/whisper-tiny.en`, ~39M params) so it runs
16
+ comfortably on the free CPU tier.
17
+
18
+ ## How it works
19
+
20
+ - The browser streams short microphone chunks to the app via
21
+ `gr.Audio(streaming=True)`.
22
+ - Each chunk is appended to a rolling buffer (capped at 30s so latency
23
+ stays low during long sessions).
24
+ - The Whisper pipeline re-transcribes the buffer on every chunk, so the
25
+ textbox updates live as you speak.
26
+ - "Clear transcript" resets the buffer.
27
+
28
+ ## Run locally
29
+
30
+ ```bash
31
+ pip install -r requirements.txt
32
+ python app.py
33
+ ```
34
+
35
+ ## Swapping the model
36
+
37
+ Edit `MODEL_ID` in `app.py`:
38
+ - `openai/whisper-tiny.en` — fastest, English-only (default)
39
+ - `openai/whisper-base.en` — a bit more accurate, still fast, English-only
40
+ - `openai/whisper-tiny` — multilingual, similar speed to tiny.en
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Live speech-to-text demo using a small Whisper model (openai/whisper-tiny.en).
3
+
4
+ The mic streams short audio chunks to the browser -> Gradio -> this function.
5
+ We keep a rolling buffer of raw audio (capped to a max length so the demo
6
+ stays responsive over long sessions) and re-run the ASR model on the buffer
7
+ each time a new chunk arrives, giving the effect of "live" transcription.
8
+ """
9
+
10
+ import numpy as np
11
+ import gradio as gr
12
+ from transformers import pipeline
13
+
14
+ # --- Model -------------------------------------------------------------
15
+ # whisper-tiny.en is ~39M params, English-only, and fast enough to run on
16
+ # CPU in near real time. Swap for "openai/whisper-base.en" for a bit more
17
+ # accuracy at the cost of latency, or "openai/whisper-tiny" for multilingual.
18
+ MODEL_ID = "openai/whisper-tiny.en"
19
+
20
+ transcriber = pipeline(
21
+ "automatic-speech-recognition",
22
+ model=MODEL_ID,
23
+ chunk_length_s=30,
24
+ )
25
+
26
+ # Cap how much audio we keep in the rolling buffer (seconds). Prevents the
27
+ # transcription from getting slower and slower the longer someone talks.
28
+ MAX_BUFFER_SECONDS = 30
29
+
30
+
31
+ def transcribe(stream, new_chunk):
32
+ sr, audio = new_chunk
33
+
34
+ # Normalize to float32 in [-1, 1]
35
+ audio = audio.astype(np.float32)
36
+ max_abs = np.max(np.abs(audio)) if audio.size else 0.0
37
+ if max_abs > 0:
38
+ audio = audio / max_abs
39
+
40
+ if stream is not None:
41
+ stream = np.concatenate([stream, audio])
42
+ else:
43
+ stream = audio
44
+
45
+ # Trim buffer so it never grows unbounded.
46
+ max_samples = MAX_BUFFER_SECONDS * sr
47
+ if len(stream) > max_samples:
48
+ stream = stream[-max_samples:]
49
+
50
+ text = transcriber({"sampling_rate": sr, "raw": stream})["text"]
51
+ return stream, text
52
+
53
+
54
+ def clear_stream():
55
+ return None, ""
56
+
57
+
58
+ with gr.Blocks(title="Live Whisper Speech-to-Text") as demo:
59
+ gr.Markdown(
60
+ f"""
61
+ # 🎙️ Live Speech-to-Text
62
+ Streaming transcription powered by **{MODEL_ID}**.
63
+ Click the microphone and start talking — the transcript updates as you speak.
64
+ """
65
+ )
66
+
67
+ with gr.Row():
68
+ audio_in = gr.Audio(sources=["microphone"], streaming=True, label="Microphone")
69
+ output_text = gr.Textbox(label="Transcript", lines=8, autoscroll=True)
70
+
71
+ state = gr.State(None)
72
+ clear_btn = gr.Button("Clear transcript")
73
+
74
+ audio_in.stream(
75
+ fn=transcribe,
76
+ inputs=[state, audio_in],
77
+ outputs=[state, output_text],
78
+ )
79
+ clear_btn.click(fn=clear_stream, inputs=None, outputs=[state, output_text])
80
+
81
+ if __name__ == "__main__":
82
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio>=4.44.0
2
+ transformers>=4.44.0
3
+ torch>=2.2.0
4
+ numpy