mirror of
https://github.com/SevaSk/ecoute.git
synced 2024-12-18 20:27:56 +00:00
reenabled responder
This commit is contained in:
parent
aa9557e13b
commit
7d4df03ee1
@ -3,10 +3,12 @@ import whisper
|
||||
import torch
|
||||
import wave
|
||||
import os
|
||||
import threading
|
||||
|
||||
class AudioTranscriber:
|
||||
def __init__(self):
|
||||
self.transcript = []
|
||||
self.transcript_data = []
|
||||
self.transcript_changed_event = threading.Event()
|
||||
self.audio_model = whisper.load_model(os.getcwd() + r'\tiny.en' + '.pt')
|
||||
|
||||
def transcribe(self, audio_data):
|
||||
@ -28,7 +30,8 @@ class AudioTranscriber:
|
||||
audio_data_transcription = self.transcribe(audio_data)
|
||||
# whisper gives "you" on many null inputs
|
||||
if audio_data_transcription != '' and audio_data_transcription.lower() != 'you':
|
||||
self.transcript = [source + ": [" + audio_data_transcription + ']\n\n'] + self.transcript
|
||||
self.transcript_data = [source + ": [" + audio_data_transcription + ']\n\n'] + self.transcript_data
|
||||
self.transcript_changed_event.set()
|
||||
|
||||
def get_transcript(self):
|
||||
return "".join(self.transcript)
|
||||
return "".join(self.transcript_data)
|
@ -1,21 +1,17 @@
|
||||
import openai
|
||||
from keys import OPENAI_API_KEY
|
||||
from prompts import create_prompt, INITIAL_RESPONSE
|
||||
from prompts import create_prompt
|
||||
|
||||
openai.api_key = OPENAI_API_KEY
|
||||
|
||||
class GPTResponder:
|
||||
def __init__(self):
|
||||
self.last_response = INITIAL_RESPONSE
|
||||
|
||||
def generate_response_from_transcript(self, transcript):
|
||||
response = openai.ChatCompletion.create(
|
||||
model="gpt-3.5-turbo-0301",
|
||||
messages=[{"role": "system", "content": create_prompt(transcript)}],
|
||||
temperature = 0.0
|
||||
)
|
||||
full_response = response.choices[0].message.content
|
||||
try:
|
||||
self.last_response = full_response.split('[')[1].split(']')[0]
|
||||
except:
|
||||
pass
|
||||
def generate_response_from_transcript(transcript):
|
||||
response = openai.ChatCompletion.create(
|
||||
model="gpt-3.5-turbo-0301",
|
||||
messages=[{"role": "system", "content": create_prompt(transcript)}],
|
||||
temperature = 0.0
|
||||
)
|
||||
full_response = response.choices[0].message.content
|
||||
try:
|
||||
return full_response.split('[')[1].split(']')[0]
|
||||
except:
|
||||
return ''
|
22
main.py
22
main.py
@ -1,11 +1,12 @@
|
||||
import soundcard as sc
|
||||
import threading
|
||||
from AudioTranscriber import AudioTranscriber
|
||||
from GPTResponder import GPTResponder
|
||||
import GPTResponder
|
||||
import customtkinter as ctk
|
||||
from Microphone import Microphone
|
||||
from AudioRecorder import AudioRecorder
|
||||
import queue
|
||||
from prompts import INITIAL_RESPONSE
|
||||
|
||||
def write_in_textbox(textbox, text):
|
||||
textbox.delete("0.0", "end")
|
||||
@ -17,15 +18,22 @@ def update_transcript_UI(transcriber, textbox):
|
||||
textbox.insert("0.0", transcript_string)
|
||||
textbox.after(300, update_transcript_UI, transcriber, textbox)
|
||||
|
||||
def update_response_UI(transcriber_mic, transcriber_speaker, responder, textbox, update_interval_slider_label, update_interval_slider):
|
||||
#transcript_string = create_transcript_string(transcriber_mic, transcriber_speaker,reverse=False)
|
||||
def update_response(transcriber, last_response, textbox, update_interval_slider_label, update_interval_slider):
|
||||
textbox.configure(state="normal")
|
||||
textbox.delete("0.0", "end")
|
||||
textbox.insert("0.0", responder.last_response)
|
||||
|
||||
if transcriber.transcript_changed_event.is_set():
|
||||
transcriber.transcript_changed_event.clear()
|
||||
transcript_string = transcriber.get_transcript()
|
||||
response = GPTResponder.generate_response_from_transcript(transcript_string)
|
||||
if response != '':
|
||||
last_response = response
|
||||
|
||||
textbox.insert("0.0", last_response)
|
||||
textbox.configure(state="disabled")
|
||||
update_interval = int(update_interval_slider.get())
|
||||
update_interval_slider_label.configure(text=f"Update interval: {update_interval} seconds")
|
||||
textbox.after(int(update_interval * 1000), update_response_UI, transcriber_mic, transcriber_speaker, responder, textbox, update_interval_slider_label, update_interval_slider)
|
||||
textbox.after(int(update_interval * 1000), update_response, transcriber, last_response, textbox, update_interval_slider_label, update_interval_slider)
|
||||
|
||||
def clear_transcript_data(transcriber_mic, transcriber_speaker):
|
||||
transcriber_mic.transcript_data.clear()
|
||||
@ -87,6 +95,6 @@ if __name__ == "__main__":
|
||||
root.grid_columnconfigure(1, weight=1)
|
||||
|
||||
update_transcript_UI(global_transcriber, transcript_textbox)
|
||||
#update_response_UI(user_transcriber, transcriber_speaker, responder, response_textbox, update_interval_slider_label, update_interval_slider)
|
||||
|
||||
update_response(global_transcriber, INITIAL_RESPONSE, response_textbox, update_interval_slider_label, update_interval_slider)
|
||||
|
||||
root.mainloop()
|
Loading…
Reference in New Issue
Block a user