Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous mode not working #148

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9fde685
Update README.md for Transcribe
vivekuppal Jun 29, 2023
1483fea
Merge pull request #1 from vivekuppal/vu-readme-updates
vivekuppal Jun 29, 2023
391d728
Allow usage without a valid OPEN API key. (#2)
vivekuppal Jun 29, 2023
ab4245d
Update README.md (#3)
vivekuppal Jun 29, 2023
ebb6f2f
Allow user to choose model. Add arguments to main file.
vivekuppal Jun 29, 2023
8f5a595
Code clean up, add linting. (#4)
vivekuppal Jun 30, 2023
59d5c91
UI Text Chronology (#5)
vivekuppal Jun 30, 2023
f772bb8
Update readme with Enhancements. Allow copy of text from UI window. R…
vivekuppal Jun 30, 2023
87a38b1
Save conversation to text. (#9)
vivekuppal Jun 30, 2023
65d6dcf
Add Contextual Information to Responses (#11)
vivekuppal Jun 30, 2023
d1b3c45
Allow users to pause audio transcription. Change the default for gett…
vivekuppal Jul 3, 2023
cfca51a
Update main.py (#15)
abhinavuppal1 Jul 11, 2023
152bad3
Code reorg to separate UI code (#16)
vivekuppal Jul 12, 2023
addf17f
Add support for multiple languages (#18)
vivekuppal Jul 12, 2023
e5cda88
Easy install for non developers on windows (#20)
vivekuppal Jul 18, 2023
9896c1c
Disabled winrar UI (#22)
Adarsha-gg Jul 18, 2023
901501b
When using API, we do not need to specify language, absorb the lang p…
vivekuppal Jul 18, 2023
bd48b61
Language combo fix (#26)
Adarsha-gg Jul 19, 2023
7c9ca88
Added gdrive (#27)
Adarsha-gg Jul 19, 2023
2429c97
Allow usage of API Key in installed version of Transcribe (#28)
vivekuppal Jul 19, 2023
12ef846
updated the drive link (#30)
Adarsha-gg Jul 20, 2023
4be26c7
Add a duration class to easily measure the time taken for an operatio…
vivekuppal Jul 21, 2023
6e53b31
--api option was not working correctly (#34)
vivekuppal Jul 21, 2023
bd42b8c
Initial unit tests for the speech recognition library (#36)
vivekuppal Jul 24, 2023
af87eff
user reported defect fixes. (#39)
vivekuppal Jul 26, 2023
26cfaad
Optimize LLM usage (#40)
vivekuppal Jul 26, 2023
f8d5857
Bug fixes for exceptions observed during usage. Add further plumbing …
vivekuppal Jul 27, 2023
1356a78
Add logging infrastructure (#42)
vivekuppal Jul 27, 2023
a1cc48b
Get Response from LLM on demand (#44)
vivekuppal Jul 28, 2023
ea5f392
Models from open ai site (#43)
Adarsha-gg Jul 28, 2023
b4e03a4
List all active devices (#45)
vivekuppal Aug 1, 2023
85d09ed
Allow user to select input, output audio devices (#48)
vivekuppal Aug 21, 2023
28d1e9a
Disable mic speaker selectively (#49)
vivekuppal Aug 23, 2023
e48bdb8
Add Audio Response for LLM generated content (#50)
vivekuppal Aug 27, 2023
6baa77f
Update, upload latest binaries (#54)
Adarsha-gg Aug 30, 2023
fa55416
Multiturn prompts, bug fixes (#55)
vivekuppal Sep 5, 2023
ce5a1e1
Allow enable/disable speaker and microphone from UI (#56)
Adarsha-gg Sep 6, 2023
e445856
Update gdrive link (#58)
Adarsha-gg Sep 7, 2023
b50f58c
Bring readme up to date with current functionality. Describe content …
vivekuppal Sep 8, 2023
a7ea2cc
Continuous mode broke after updates to the UI.
vivekuppal Sep 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add logging infrastructure (#42)
  • Loading branch information
vivekuppal committed Jul 27, 2023
commit 1356a782382f20b6abe539a879da8ce72d72b2e0
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ __pycache__/
.venv/
venv
output
tiny.pt
tiny.pt
Transcribe.log
7 changes: 7 additions & 0 deletions AudioRecorder.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import custom_speech_recognition as sr
import pyaudiowpatch as pyaudio
from datetime import datetime
import app_logging as al

RECORD_TIMEOUT = 3
ENERGY_THRESHOLD = 1000
DYNAMIC_ENERGY_THRESHOLD = False

root_logger = al.get_logger()


class BaseRecorder:
def __init__(self, source, source_name):
root_logger.info(BaseRecorder.__name__)
self.recorder = sr.Recognizer()
self.recorder.energy_threshold = ENERGY_THRESHOLD
self.recorder.dynamic_energy_threshold = DYNAMIC_ENERGY_THRESHOLD
Expand All @@ -20,6 +24,7 @@ def __init__(self, source, source_name):
self.source_name = source_name

def adjust_for_noise(self, device_name, msg):
root_logger.info(BaseRecorder.adjust_for_noise.__name__)
print(f"[INFO] Adjusting for ambient noise from {device_name}. " + msg)
with self.source:
self.recorder.adjust_for_ambient_noise(self.source)
Expand All @@ -36,12 +41,14 @@ def record_callback(_, audio: sr.AudioData) -> None:

class DefaultMicRecorder(BaseRecorder):
def __init__(self):
root_logger.info(DefaultMicRecorder.__name__)
super().__init__(source=sr.Microphone(sample_rate=16000), source_name="You")
self.adjust_for_noise("Default Mic", "Please make some noise from the Default Mic...")


class DefaultSpeakerRecorder(BaseRecorder):
def __init__(self):
root_logger.info(DefaultSpeakerRecorder.__name__)
with pyaudio.PyAudio() as p:
wasapi_info = p.get_host_api_info_by_type(pyaudio.paWASAPI)
default_speakers = p.get_device_info_by_index(wasapi_info["defaultOutputDevice"])
Expand Down
1 change: 1 addition & 0 deletions AudioTranscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from heapq import merge
import conversation


PHRASE_TIMEOUT = 3.05


Expand Down
5 changes: 5 additions & 0 deletions GPTResponder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import conversation
import constants
import configuration
import app_logging as al


# Number of phrases to use for generating a response
MAX_PHRASES = 20
root_logger = al.get_logger()


class GPTResponder:
def __init__(self, convo: conversation.Conversation):
root_logger.info(GPTResponder.__name__)
self.response = prompts.INITIAL_RESPONSE
self.response_interval = 2
self.gl_vars = GlobalVars.TranscriptionGlobals()
Expand Down Expand Up @@ -80,4 +84,5 @@ def respond_to_transcriber(self, transcriber):
time.sleep(0.3)

def update_response_interval(self, interval):
root_logger.info(GPTResponder.update_response_interval.__name__)
self.response_interval = interval
4 changes: 4 additions & 0 deletions GlobalVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import AudioRecorder
import customtkinter as ctk
import Singleton
import app_logging as al


root_logger = al.get_logger()

class TranscriptionGlobals(Singleton.Singleton):
"""Global constants for audio processing. It is implemented as a Singleton class.
"""
Expand All @@ -22,6 +25,7 @@ class TranscriptionGlobals(Singleton.Singleton):
api_key: str = None

def __init__(self, key: str = 'API_KEY'):
root_logger.info(TranscriptionGlobals.__name__)
if self.audio_queue is None:
self.audio_queue = queue.Queue()
if self.user_audio_recorder is None:
Expand Down
26 changes: 26 additions & 0 deletions app_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import queue
import logging
from logging import handlers
import constants


root_logger: logging.Logger = logging.getLogger(name=constants.LOG_NAME)


def initiate_log(config: dict) -> handlers.QueueListener:
# Initiate logging
que = queue.Queue(-1)
queue_handler = handlers.QueueHandler(que)
handler = logging.FileHandler(config['General']['log_file'], mode='w', encoding='utf-8')
log_listener = handlers.QueueListener(que, handler)
root_logger.setLevel(level=logging.INFO)
root_logger.addHandler(queue_handler)
log_formatter = logging.Formatter('%(asctime)s %(levelname)s %(threadName)s: %(message)s')
handler.setFormatter(log_formatter)
log_listener.start()
root_logger.info('Logging started for application!')
return log_listener


def get_logger() -> logging.Logger:
return root_logger
10 changes: 6 additions & 4 deletions constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Globally used constants
"""

PERSONA_YOU = "You"
PERSONA_ASSISTANT = "Assistant"
PERSONA_SYSTEM = "System"
PERSONA_SPEAKER = "Speaker"
PERSONA_YOU = 'You'
PERSONA_ASSISTANT = 'Assistant'
PERSONA_SYSTEM = 'System'
PERSONA_SPEAKER = 'Speaker'

LOG_NAME = 'Transcribe'
5 changes: 5 additions & 0 deletions interactions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import subprocess
import socket
import app_logging as al


root_logger = al.get_logger()


def create_params() -> dict:
try:
root_logger.info(create_params.__name__)
git_version = subprocess.check_output(
['git', 'rev-parse', '--short', 'HEAD']).decode("utf-8").strip()
except subprocess.CalledProcessError as process_exception:
Expand Down
30 changes: 20 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
import TranscriberModels
import interactions
import ui
from language import LANGUAGES_DICT
import GlobalVars
import configuration
import conversation
import app_logging


def main():
# Set up all arguments
Expand Down Expand Up @@ -47,10 +48,23 @@ def main():
line argument. Behavior is undefined.')
args = cmd_args.parse_args()

# Initiate config
config = configuration.Config().get_data()

# Initiate global variables
# Two calls to GlobalVars.TranscriptionGlobals is on purpose
global_vars = GlobalVars.TranscriptionGlobals()

global_vars = GlobalVars.TranscriptionGlobals(key=config["OpenAI"]["api_key"])

# Initiate logging
log_listener = app_logging.initiate_log(config=config)

try:
subprocess.run(["ffmpeg", "-version"],
stdout = subprocess.DEVNULL,
stderr = subprocess.DEVNULL)
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=True)
except FileNotFoundError:
print("ERROR: The ffmpeg library is not installed. Please install \
ffmpeg and try again.")
Expand All @@ -64,13 +78,6 @@ def main():
except ConnectionError:
print('[INFO] Operating in Desktop mode')

config = configuration.Config().get_data()

# Two calls to GlobalVars.TranscriptionGlobals is on purpose
global_vars = GlobalVars.TranscriptionGlobals()

global_vars = GlobalVars.TranscriptionGlobals(key=config["OpenAI"]["api_key"])

# Command line arg for api_key takes preference over api_key specified in parameters.yaml file
if args.api_key is not None:
api_key = args.api_key
Expand Down Expand Up @@ -104,13 +111,15 @@ def main():
model,
convo=convo)
transcribe_thread = threading.Thread(target=global_vars.transcriber.transcribe_audio_queue,
name='Transcribe',
args=(global_vars.audio_queue,))
transcribe_thread.daemon = True
transcribe_thread.start()

global_vars.responder = GPTResponder(convo=convo)

respond_thread = threading.Thread(target=global_vars.responder.respond_to_transcriber,
name='Respond',
args=(global_vars.transcriber,))
respond_thread.daemon = True
respond_thread.start()
Expand All @@ -136,6 +145,7 @@ def main():
update_interval_slider, global_vars.freeze_state)

root.mainloop()
log_listener.stop()


if __name__ == "__main__":
Expand Down
3 changes: 3 additions & 0 deletions parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ OpenAI:
# See this link for available models
# https://platform.openai.com/docs/models/continuous-model-upgrades
ai_model: gpt-3.5-turbo-0301

General:
log_file: 'Transcribe.log'
9 changes: 9 additions & 0 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import customtkinter as ctk
import GlobalVars
import GPTResponder
import app_logging as al


root_logger = al.get_logger()
UI_FONT_SIZE = 20


Expand All @@ -21,23 +24,27 @@ def __init__(self):
def copy_to_clipboard(self):
"""Copy transcription text data to clipboard
"""
root_logger.info(ui_callbacks.copy_to_clipboard.__name__)
pyperclip.copy(self.global_vars.transcriber.get_transcript())

def save_file(self):
"""Save transcription text data to file
"""
root_logger.info(ui_callbacks.save_file.__name__)
filename = ctk.filedialog.asksaveasfilename()
with open(file=filename, mode="w", encoding='utf-8') as file_handle:
file_handle.write(self.global_vars.transcriber.get_transcript())

def freeze_unfreeze(self):
"""Respond to start / stop of seeking responses from openAI API"""
root_logger.info(ui_callbacks.freeze_unfreeze.__name__)
self.global_vars.freeze_state[0] = not self.global_vars.freeze_state[0] # Invert the state
self.global_vars.freeze_button.configure(
text="Suggest Response" if self.global_vars.freeze_state[0] else "Do Not Suggest Response"
)

def set_transcript_state(self):
root_logger.info(ui_callbacks.set_transcript_state.__name__)
self.global_vars.transcriber.transcribe = not self.global_vars.transcriber.transcribe
self.global_vars.transcript_button.configure(
text="Pause Transcript" if self.global_vars.transcriber.transcribe else "Start Transcript"
Expand Down Expand Up @@ -99,12 +106,14 @@ def clear_transcriber_context(transcriber: AudioTranscriber,
textbox: textbox to be updated
text: updated text
"""
root_logger.info(clear_transcriber_context.__name__)
transcriber.clear_transcript_data()
with audio_queue.mutex:
audio_queue.queue.clear()


def create_ui_components(root):
root_logger.info(create_ui_components.__name__)
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("dark-blue")
root.title("Transcribe")
Expand Down