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
UI Text Chronology (#5)
* Show all text in chronological order instead of current behavior of showing only the last MAX_PHRASES(10) items. Use the last MAX_PHRASES(10) for generating a response to the conversation.

* Remove print statements, debugging code.

* Remove references to Git LFS. Add a note about models.
  • Loading branch information
vivekuppal committed Jun 30, 2023
commit 59d5c91e6e71538f2cb16c4d404e04884b28c0ab
34 changes: 16 additions & 18 deletions AudioTranscriber.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import whisper
import torch
import wave
import os
import threading
import tempfile
import custom_speech_recognition as sr
import io
from datetime import timedelta
import wave
import tempfile
import whisper
import torch
import custom_speech_recognition as sr
import pyaudiowpatch as pyaudio
from heapq import merge

PHRASE_TIMEOUT = 3.05

MAX_PHRASES = 10

class AudioTranscriber:
def __init__(self, mic_source, speaker_source, model):
Expand Down Expand Up @@ -52,8 +51,8 @@ def transcribe_audio_queue(self, audio_queue):
os.close(fd)
source_info["process_data_func"](source_info["last_sample"], path)
text = self.audio_model.get_transcription(path)
except Exception as e:
print(e)
except Exception as exception:
print(exception)
finally:
os.unlink(path)

Expand Down Expand Up @@ -91,19 +90,18 @@ def update_transcript(self, who_spoke, text, time_spoken):
transcript = self.transcript_data[who_spoke]

if source_info["new_phrase"] or len(transcript) == 0:
if len(transcript) > MAX_PHRASES:
transcript.pop(-1)
transcript.insert(0, (f"{who_spoke}: [{text}]\n\n", time_spoken))
transcript.append((f"{who_spoke}: [{text}]\n\n", time_spoken))
else:
transcript[0] = (f"{who_spoke}: [{text}]\n\n", time_spoken)
transcript.pop()
transcript.append((f"{who_spoke}: [{text}]\n\n", time_spoken))

def get_transcript(self):
def get_transcript(self, length: int = 0):
combined_transcript = list(merge(
self.transcript_data["You"], self.transcript_data["Speaker"],
key=lambda x: x[1], reverse=True))
combined_transcript = combined_transcript[:MAX_PHRASES]
self.transcript_data["You"], self.transcript_data["Speaker"],
key=lambda x: x[1], reverse=False))
combined_transcript = combined_transcript[-length:]
return "".join([t[0] for t in combined_transcript])

def clear_transcript_data(self):
self.transcript_data["You"].clear()
self.transcript_data["Speaker"].clear()
Expand All @@ -112,4 +110,4 @@ def clear_transcript_data(self):
self.audio_sources["Speaker"]["last_sample"] = bytes()

self.audio_sources["You"]["new_phrase"] = True
self.audio_sources["Speaker"]["new_phrase"] = True
self.audio_sources["Speaker"]["new_phrase"] = True
15 changes: 9 additions & 6 deletions GPTResponder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@
import time

openai.api_key = OPENAI_API_KEY
# Number of phrases to use for generating a response
MAX_PHRASES = 10

def generate_response_from_transcript(transcript):
try:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0301",
messages=[{"role": "system", "content": create_prompt(transcript)}],
temperature = 0.0
temperature=0.0
)
except Exception as e:
print(e)
except Exception as exception:
print(exception)
return ''
full_response = response.choices[0].message.content
try:
return full_response.split('[')[1].split(']')[0]
except:
return ''



class GPTResponder:
def __init__(self):
self.response = INITIAL_RESPONSE
Expand All @@ -32,7 +35,7 @@ def respond_to_transcriber(self, transcriber):
start_time = time.time()

transcriber.transcript_changed_event.clear()
transcript_string = transcriber.get_transcript()
transcript_string = transcriber.get_transcript(length=MAX_PHRASES)
response = generate_response_from_transcript(transcript_string)

end_time = time.time() # Measure end time
Expand All @@ -48,4 +51,4 @@ def respond_to_transcriber(self, transcriber):
time.sleep(0.3)

def update_response_interval(self, interval):
self.response_interval = interval
self.response_interval = interval
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ Follow these steps to set up and run transcribe on your local machine.
- Python >=3.8.0
- (Optional) An OpenAI API key that can access OpenAI API (set up a paid account OpenAI account)
- Windows OS (Not tested on others)
- Git LFS

Install [Git LFS](https://git-lfs.com/)

Run the command
```
git lfs install
```

- FFmpeg

If FFmpeg is not installed in your system, follow the steps below to install it.
Expand Down Expand Up @@ -101,6 +92,8 @@ While Transcribe provides real-time transcription and optional response suggesti
Incorrect API key provided: API_KEY. You can find your API key at https://platform.openai.com/account/api-keys.
```

**Models**: The default install of transcribe has the tiny(72 Mb) model. base (138 Mb), small (461 Mb) models can be downloaded and used for transcription by following instructions using transcribe command line. The larger models provide better quality transcription and they have higher memory requirements.

**Language**: If you are not using the --api flag the Whisper model used in Transcribe is set to English. As a result, it may not accurately transcribe non-English languages or dialects.

## 📖 License
Expand Down
2 changes: 1 addition & 1 deletion keys.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
OPENAI_API_KEY="API_KEY"
OPENAI_API_KEY = "API_KEY"
11 changes: 8 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def write_in_textbox(textbox, text):
def update_transcript_UI(transcriber, textbox):
transcript_string = transcriber.get_transcript()
write_in_textbox(textbox, transcript_string)
textbox.see("end")
textbox.after(300, update_transcript_UI, transcriber, textbox)


Expand Down Expand Up @@ -89,9 +90,12 @@ def main():
help='Use the online Open AI API for transcription.\
\nThis option requires an API KEY and will consume Open AI credits.')
cmd_args.add_argument('-m', '--model', action='store', choices=['tiny', 'base', 'small'], default='tiny',
help='Specify the model to use for transcription.'\
'\nOpenAI has more models besides the ones specified above.'\
'\nThose models are prohibitive to use on local machines because of memory requirements.'\
help='Specify the model to use for transcription.'
'\nBy default tiny model is part of the install.'
'\nbase model has to be downloaded from the link https://drive.google.com/file/d/1E44DVjpfZX8tSrSagaDJXU91caZOkwa6/view?usp=drive_link'
'\nsmall model has to be downloaded from the link https://drive.google.com/file/d/1E44DVjpfZX8tSrSagaDJXU91caZOkwa6/view?usp=drive_link'
'\nOpenAI has more models besides the ones specified above.'
'\nThose models are prohibitive to use on local machines because of memory requirements.'
'\nThis option is only applicable when not using the --api option.')
args = cmd_args.parse_args()

Expand All @@ -118,6 +122,7 @@ def main():
speaker_audio_recorder.record_into_queue(audio_queue)
model = TranscriberModels.get_model(args.api, model=args.model)

# Transcribe and Respond threads, both work on the same instance of the AudioTranscriber class
transcriber = AudioTranscriber(user_audio_recorder.source,
speaker_audio_recorder.source, model)
transcribe = threading.Thread(target=transcriber.transcribe_audio_queue,
Expand Down