Skip to content

Commit

Permalink
🔨 Adds profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Sajus committed Dec 16, 2023
1 parent 5056c07 commit 7bd5325
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
from os import PathLike
from time import time
import asyncio
from dotenv import load_dotenv
from typing import List, Optional, TypeVar, Union, IO
from typing import Union

import openai
from deepgram import Deepgram
from gtts import gTTS
import pygame
from pygame import mixer
import elevenlabs
Expand Down Expand Up @@ -71,28 +71,35 @@ async def transcribe(
if __name__ == "__main__":
while True:
# Record audio
print("Listening...", end="")
print("Listening...")
SpeechToText()
print("Done listening.")
# Transcribe audio
print("Transcribing...")
current_time = time()
deepgram = Deepgram(DEEPGRAM_API_KEY)
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
words = loop.run_until_complete(transcribe(RECORDING_PATH))
string_words = " ".join(
word_dict.get("word") for word_dict in words if "word" in word_dict
)
transcription_time = time() - current_time
print(f"Finished transcribing in {transcription_time:.2f} seconds.")
# Get response from GPT-3
print("Generating response...")
current_time = time()
context += f"\nAlex: {string_words}\nJarvis: "
response = request_gpt(context)
context += response
gpt_time = time() - current_time
print(f"Finished generating response in {gpt_time:.2f} seconds.")
# Convert response to audio
print("Converting to audio...")
current_time = time()
audio = elevenlabs.generate(
text=response, voice="Adam", model="eleven_monolingual_v1"
)
elevenlabs.save(audio, "wavs/response.wav")
audio_time = time() - current_time
print(f"Finished generating audio in {audio_time:.2f} seconds.")
# Play response
print("Speaking...")
sound = mixer.Sound("wavs/response.wav")
Expand Down

0 comments on commit 7bd5325

Please sign in to comment.