Skip to content

Instantly share code, notes, and snippets.

@ssghost
Forked from Vaibhavs10/live_whisper_inference.py
Created January 26, 2023 00:15
Show Gist options
  • Save ssghost/954b834561c0e366a17fa4ea9eb6dd36 to your computer and use it in GitHub Desktop.
Save ssghost/954b834561c0e366a17fa4ea9eb6dd36 to your computer and use it in GitHub Desktop.
#pip install git+https://github.com/huggingface/transformers.git
import datetime
import sys
from transformers import pipeline
from transformers.pipelines.audio_utils import ffmpeg_microphone_live
pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=0)
sampling_rate = pipe.feature_extractor.sampling_rate
start = datetime.datetime.now()
chunk_length_s = 5
stream_chunk_s = 0.1
mic = ffmpeg_microphone_live(
sampling_rate=sampling_rate,
chunk_length_s=chunk_length_s,
stream_chunk_s=stream_chunk_s,
)
print("Start talking...")
for item in pipe(mic):
sys.stdout.write("\033[K")
print(item["text"], end="\r")
if not item["partial"][0]:
print("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment