Skip to content

Commit

Permalink
fixed typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Jef808 committed Feb 5, 2024
1 parent 7454cdd commit c3d7a2e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 583 deletions.
34 changes: 18 additions & 16 deletions listener/listener_with_wake_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@

PROJECT_ROOT = Path(os.getenv('PROJECT_ROOT'))
CHEETAH_MODEL_FILE = PROJECT_ROOT / "listener/data/speech-command-cheetah-v1.pv"
PORCUPINE_MODEL_FILE = PROJECT_ROOT / "listener/data/laptop_en_linux_v3_0_0.ppn"
PORCUPINE_LAPTOP_KEYWORD_FILE = PROJECT_ROOT / "listener/data/laptop_en_linux_v3_0_0.ppn"
TRANSCRIPT_BEGIN_WAV = PROJECT_ROOT / "listener/data/transcript_begin.wav"
TRANSCRIPT_SUCCESS_WAV = PROJECT_ROOT / "listener/data/transcript_success.wav"

SOCKET_PATH = "/tmp/transcript_socket"
SOCKET_PATH = Path(os.getenv('XDG_RUNTIME_DIR')) / "transcription"


@contextmanager
def porcupine_context_manager(keywords, sensitivities):
def porcupine_context_manager(keyword_paths, sensitivities):
"""Create a Porcupine instance and yield it. Delete the instance upon exit."""
porcupine_instance = None
try:
porcupine_instance = pvporcupine.create(
keywords=keywords,
keyword_paths=keyword_paths,
sensitivities=sensitivities,
access_key=os.getenv('PICOVOICE_API_KEY'),
model_path=PORCUPINE_MODEL_FILE
access_key=os.getenv('PICOVOICE_API_KEY')
)
yield porcupine_instance
finally:
Expand All @@ -40,9 +38,11 @@ def cheetah_context_manager():
"""Create a Cheetah instance and yield it. Delete the instance upon exit."""
cheetah_instance = None
try:
cheetah_instance = pvcheetah.create(access_key=os.getenv('PICOVOICE_API_KEY'),
endpoint_duration_sec=1.3,
model_path=str(CHEETAH_MODEL_FILE))
cheetah_instance = pvcheetah.create(
access_key=os.getenv('PICOVOICE_API_KEY'),
endpoint_duration_sec=1.3,
model_path=str(CHEETAH_MODEL_FILE)
)
yield cheetah_instance
finally:
if cheetah_instance:
Expand Down Expand Up @@ -73,8 +73,11 @@ def play_sound(wav_file):

def main():
"""Upon detection of a wake word, transcribe speech until endpoint is detected."""
keywords = ["computer", "laptop"]
sensitivities = [0.1]
keywords = ["computer"]
keyword_paths = [PORCUPINE_LAPTOP_KEYWORD_FILE]
keyword_paths.extend(pvporcupine.KEYWORD_PATHS[w] for w in keywords)
keywords = [Path(w).stem.split('_')[0] for w in keyword_paths]
sensitivities = [0.1] * len(keyword_paths)
device_index = -1
frame_length = 512

Expand All @@ -84,12 +87,11 @@ def console_status(flag):
client = None

try:
with porcupine_context_manager(keywords, sensitivities) as porcupine, \
with porcupine_context_manager(keyword_paths, sensitivities) as porcupine, \
cheetah_context_manager() as cheetah, \
recorder_context_manager(device_index, frame_length) as recorder:

wake_word_detected = False
is_endpoint = False

while True:
pcm_frame = recorder.read()
Expand All @@ -99,7 +101,7 @@ def console_status(flag):
if keyword_index >= 0:
wake_word_detected = True
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
client.connect(SOCKET_PATH)
client.connect(str(SOCKET_PATH))
play_sound(TRANSCRIPT_BEGIN_WAV)

else:
Expand All @@ -119,7 +121,7 @@ def console_status(flag):
print(f"An error occured: {e}", file=sys.stderr)
finally:
if client is not None:
client.sendall('STOP'.encode())
client.sendall(b'STOP')
client.close()


Expand Down
13 changes: 7 additions & 6 deletions listener/socket_read.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python3

import socket
import os
from pathlib import Path
import socket
import subprocess

SOCKET_PATH = "/tmp/transcript_socket"
SOCKET_PATH = Path(os.getenv('XDG_RUNTIME_DIR')) / "transcription"
n_connections = 0


Expand Down Expand Up @@ -40,13 +41,13 @@ def handle_client(client_socket, client_address):
def main():
"""Listen for connections and handle them."""
try:
os.unlink(SOCKET_PATH)
SOCKET_PATH.unlink()
except OSError:
if os.path.exists(SOCKET_PATH):
if SOCKET_PATH.exists():
raise

with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as server_socket:
server_socket.bind(SOCKET_PATH)
server_socket.bind(str(SOCKET_PATH))
server_socket.listen(1)

try:
Expand All @@ -57,7 +58,7 @@ def main():
else:
handle_client(client_socket, client_address)
finally:
os.unlink(SOCKET_PATH)
SOCKET_PATH.unlink()


if __name__ == '__main__':
Expand Down
1 change: 0 additions & 1 deletion speech-to-intent/intent_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import json
from pathlib import Path
import sqlite3
import numpy as np
import pandas as pd

shell_history_query = r"""select strftime(case when datetime(max_start, 'unixepoch') > datetime('now', 'start of day') then '%H:%M' else '%d/%m' end, max_start, 'unixepoch', 'localtime') as time, session as ses, dir, argv as cmd from (select session, replace(places.dir, '/home/jfa', '~') as dir, replace(commands.argv, '
Expand Down
Empty file removed speech-to-text/__init__.py
Empty file.
Loading

0 comments on commit c3d7a2e

Please sign in to comment.