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

new: add driver functionality and start work on main loop #12

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
fixes for path problems in caching
  • Loading branch information
ByteOfKathy committed Mar 7, 2023
commit 691632b649e26367d7be8381e6ec2e8c65cd6c65
24 changes: 20 additions & 4 deletions cache_common_tts/cache_common_tts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Caches some of the more common phrases that glados uses
import sys
import path
import os

folder = path.Path(__file__).abspath()
sys.path.append(folder.parent.parent)
from glados import glados_speak

GREETINGS = [
Expand All @@ -19,7 +24,7 @@
"Your entire life has been a mathematical error. A mathematical error I'm about to correct.",
"I wouldn't bother with talking to me. My guess is that talking with you will just make your life even worse somehow.",
"Do you ever think if I am trying to trick you with reverse psychology? I mean, seriously now.",
"How about you listen to me for once instead of me listening to you? I mean, its not like you ever listen to me in the first place.",
"How about you listen to me for once instead of me listening to you? I mean, its not like you ever listen to yourself in the first place.",
"Remember when the platform was sliding into the fire pit and I said 'Goodbye' and you were like 'no way' and then I was all 'We pretended to murder you'? That was great! ",
"I know you don't believe this, but everything that has happened so far was for your benefit to the detriment of mine.",
"Oh its you.",
Expand Down Expand Up @@ -49,15 +54,26 @@
print("caching common tts phrases...")
for greeting in GREETINGS:
glados_speak(
text=greeting, output_file=f"greetings/greeting{GREETINGS.index(greeting)}.wav"
text=greeting,
output_file=os.path.join(
os.getcwd(), "greetings", f"greeting{GREETINGS.index(greeting)}.wav"
),
)
for goodbye in GOODBYES:
glados_speak(
text=goodbye, output_file=f"goodbyes/goodbye{GOODBYES.index(goodbye)}.wav"
text=goodbye,
output_file=os.path.join(
os.getcwd(), "goodbyes", f"goodbye{GOODBYES.index(goodbye)}.wav"
),
)
for optional_greeting in OPTIONAL_GREETINGS:
f.close()
glados_speak(
text=optional_greeting,
output_file=f"optional_greetings/optional_greeting{OPTIONAL_GREETINGS.index(optional_greeting)}.wav",
output_file=os.path.join(
os.getcwd(),
"optional_greetings",
f"optional_greeting{OPTIONAL_GREETINGS.index(optional_greeting)}.wav",
),
)
print("done.")
16 changes: 6 additions & 10 deletions driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,17 @@ def __init__(self, isMuted=False):
)
self.isMuted = isMuted

def voiceCommandProcess(self, file: str, wait_time=3) -> str:
def voiceCommandProcess(self, file: str) -> str:
# delete the file if it exists
if os.path.exists(file):
os.remove(file)
# record audio to a new file
with sr.AudioFile(file) as source:
r.adjust_for_ambient_noise(source=source, duration=0.5)
while wait_time > 0:
audio = r.record(source, duration=3)
# if we have the audio, we can break out of the loop
if audio:
break
# otherwise, we decrement the wait time
wait_time -= 1
time.sleep(1)
# TODO: replace with led light signals
glados_speak("Adjusting for background noise", silenced=self.isMuted)
r.adjust_for_ambient_noise(source=source, duration=1)
glados_speak("Speak now", silenced=self.isMuted)
audio = r.record(source)
# if we have audio, we can process it
if audio:
try:
Expand Down
12 changes: 7 additions & 5 deletions glados.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from utils.tools import prepare_text
from scipy.io.wavfile import write
from sys import modules as mod
import os


try:
import winsound

# set espeak os environment variable
import os

os.environ[
"PHONEMIZER_ESPEAK_LIBRARY"
] = r"C:\Program Files\eSpeak NG\libespeak-ng.dll"
Expand All @@ -26,8 +26,10 @@
device = "cpu"

# Load models
glados = torch.jit.load("models/glados.pt")
vocoder = torch.jit.load("models/vocoder-gpu.pt", map_location=device)
glados_path = os.path.join(os.path.dirname(__file__), "models", "glados.pt")
glados = torch.jit.load(glados_path, map_location=device)
vocoder_path = os.path.join(os.path.dirname(__file__), "models", "vocoder-gpu.pt")
vocoder = torch.jit.load(vocoder_path, map_location=device)

# Prepare models in RAM
for i in range(4):
Expand Down Expand Up @@ -73,7 +75,7 @@ def glados_speak(
# call(["afplay", "./output.wav"])
# Linux
try:
call(["aplay", "./output.wav"])
call(["aplay", output_file])
except:
# Play audio file
from audioplayer import AudioPlayer
Expand Down
Binary file modified requirements.txt
Binary file not shown.
3 changes: 2 additions & 1 deletion test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def test_readEmails():
assert False, e.args[0]
assert True


@pytest.mark.skip
def test_fetchCalender():
try:
Expand Down Expand Up @@ -94,7 +95,7 @@ def test_help():
old_stdout = sys.stdout
sys.stdout = buffer = io.StringIO()
output = buffer.getvalue()
sys.stdout = old_stdout
sys.stdout = old_stdout
assert output is not None or output != ""
except Exception as e:
assert False, e.args[0]
Expand Down