Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /gradio-app_gradio /demo /stream_asr /run.py
| import gradio as gr | |
| from transformers import pipeline | |
| import numpy as np | |
| transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en") | |
| def transcribe(stream, new_chunk): | |
| sr, y = new_chunk | |
| # Convert to mono if stereo | |
| if y.ndim > 1: | |
| y = y.mean(axis=1) | |
| y = y.astype(np.float32) | |
| y /= np.max(np.abs(y)) | |
| if stream is not None: | |
| stream = np.concatenate([stream, y]) | |
| else: | |
| stream = y | |
| return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"] # type: ignore | |
| demo = gr.Interface( | |
| transcribe, | |
| ["state", gr.Audio(sources=["microphone"], streaming=True)], | |
| ["state", "text"], | |
| live=True, | |
| api_name="predict" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |
Xet Storage Details
- Size:
- 774 Bytes
- Xet hash:
- 8c493c71dc7f695c20192861f40cb94ee8035a4cb4e70b7d5696e98fd0c28d5e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.