Spaces:
Running
Running
| import gradio as gr | |
| from transformers import pipeline | |
| import numpy as np | |
| #from google.cloud import speech_v1 | |
| #from google.protobuf import timestamp_pb2 | |
| transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en") | |
| def transcribe(stream, audio_bytes): | |
| """Transcribe audio bytes to text using Google Cloud Speech to Text.""" | |
| sr, y = audio_bytes | |
| 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"] | |
| demo = gr.Interface( | |
| transcribe, | |
| ["state", gr.Audio(sources=["microphone"], streaming=False)], | |
| ["state", "text"], | |
| live=True, | |
| ) | |
| demo.launch() | |