Skip to content

Commit

Permalink
Added correct files and updated setup script
Browse files Browse the repository at this point in the history
Signed-off-by: Rishi <[email protected]>
  • Loading branch information
rshrc committed Sep 21, 2023
1 parent eff4863 commit 67d588c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 24 deletions.
30 changes: 10 additions & 20 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from functools import wraps
from io import BytesIO
from tempfile import TemporaryFile
# from display.utils import display
from oled.lib import DisplayController
import nltk
import requests as r
Expand All @@ -20,13 +19,10 @@
from nltk.tokenize import sent_tokenize, word_tokenize
from pydub import AudioSegment
from pydub.playback import play

from mem_test import measure_memory_usage


os.environ['ALSA_WARNINGS'] = '0'
# nltk.download('averaged_perceptron_tagger')
# nltk.download('punkt')

def timing(f):

Expand Down Expand Up @@ -64,8 +60,6 @@ def timed(*args, **kw):
# Example Usage:
dpc = DisplayController()



@timing # taking 0.0019 sec
@measure_memory_usage
def check_similar_song(user_input: str):
Expand Down Expand Up @@ -147,14 +141,10 @@ def update_conversation(input, output):
@measure_memory_usage
async def process_input(recognized_text):
# doc = nlp(recognized_text)
dpc.render_text("Let me think....")
try:
tokens = word_tokenize(recognized_text)
tagged_tokens = pos_tag(tokens)

# 0.00012 seconds in intent detection
# play_intent = any(token.text.lower() in play_keywords or token.pos_ == "VERB" for token in doc)
# stop_intent = any(token.text.lower() in stop_keywords or token.pos_ == "VERB" for token in doc)

play_intent = any(word.lower() in play_keywords or pos ==
"VB" for word, pos in tagged_tokens)
stop_intent = any(word.lower() in stop_keywords or pos ==
Expand All @@ -163,6 +153,8 @@ async def process_input(recognized_text):
except Exception as e:
play_intent = False
stop_intent = False
print(f"HMMM!!!!! What the fuck! {e}")
return

print(f"Play Intent? {play_intent}")
print(f"Stop Intent? {stop_intent}")
Expand Down Expand Up @@ -212,6 +204,7 @@ def voice_filler():

@measure_memory_usage
async def speech_to_text():

with sr.Microphone() as source:

recognizer.adjust_for_ambient_noise(source)
Expand All @@ -222,7 +215,7 @@ async def speech_to_text():
print("Listening for Wake Word")
dpc.render_text("Listening for wake word")
audio = recognizer.listen(source)

dpc.render_text("Hmmmmmm.....")
print("There was some audio input!")

try:
Expand All @@ -231,23 +224,20 @@ async def speech_to_text():

wake_word = fuzz.partial_ratio(recognized_text, WAKE_WORD)
yes_wake_word = fuzz.partial_ratio(
recognized_text, f"yes google")
recognized_text, f"hey panda")

print(f"Wake Word Spoken: {wake_word}")

if wake_word > 70:
if recognized_text.lower().startswith(WAKE_WORD) and len(recognized_text) == len(WAKE_WORD):
while True:
# TODO: Trigger LED LIGHT
# response = await output_voice(voice_filler(), expect_return=True)

print("ARE WE READY TO LISTEN")
print("Microphone is back Online")
print("Preparing for Audio I/O")

print("Listeing for second command!")
dpc.render_text(voice_filler())
audio = recognizer.listen(source)

print("I GUESS WE ARE")
dpc.render_text("Ummm...")
print("Resuming Conversation")

recognized_text = recognizer.recognize_google(
audio)
Expand Down
Binary file modified nlp/averaged_perceptron_tagger.zip
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 11 additions & 2 deletions oled/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import board
from PIL import Image, ImageDraw, ImageFont
from adafruit_rgb_display import ili9341
import threading

class DisplayController:
def __init__(self):
Expand Down Expand Up @@ -66,6 +67,14 @@ def clear_screen(self):
def display_image(self):
self.disp.image(self.image)

# Example Usage:
# # Example Usage:
# controller = DisplayController()
# controller.render_text("Ramkrishna Paramahamsa Ki Jai!")

# def display_thread(text):
# controller.render_text(text)

# display_thread = threading.Thread(target=display_thread)

# # Running Display Parallelly
# display_thread.start()

4 changes: 2 additions & 2 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ sudo pip3 install -r requirements.txt

# Setup NLP
# Unzip file1.zip and rename to nlp1
unzip nlp/nlp1.zip -d temp_folder && mv temp_folder/* nltk_data/ && rm -r temp_folder
unzip nlp/punkt.zip -d temp_folder && mv temp_folder/* /home/rishi/nltk_data/tokenizers/ && rm -r temp_folder

# Unzip file2.zip and rename to nlp2
unzip nlp/nlp2.zip -d temp_folder && mv temp_folder/* nltk_data/ && rm -r temp_folder
unzip nlp/averaged_perceptron_tagger.zip -d temp_folder && mv temp_folder/* /home/rishi/taggers/ && rm -r temp_folder

# Additional setup tasks (add your own commands here)
# Example: Enable SSH, configure Wi-Fi, etc.
Expand Down

0 comments on commit 67d588c

Please sign in to comment.