transcriber-prompt / GUI /real-time.py
harshp8l's picture
Upload folder using huggingface_hub
9690d29
raw
history blame contribute delete
No virus
734 Bytes
import whisper
import pyaudio
import tkinter as tk
# PyAudio config
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
# Create GUI
root = tk.Tk()
text_box = tk.Text(root)
text_box.pack()
# Load Whisper
model = whisper.load_model("base")
# Start audio stream
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
# Listen to mic in a loop
while True:
data = stream.read(CHUNK)
text = model.transcribe(data)['text']
# Insert into GUI
text_box.insert('end', text)
text_box.see('end')
root.update()
stream.stop_stream()
stream.close()
p.terminate()