Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kenarsa committed May 16, 2024
1 parent 0192975 commit bef7789
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
27 changes: 27 additions & 0 deletions recipes/llm-voice-assistant/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,30 @@

- Python 3.8+
- Runs on Linux (x86_64), macOS (arm64, x86_64), Windows (x86_64), and Raspberry Pi (5, 4, and 3).

## AccessKey

## picoLLM Model

## Custom Wake Word (Optional)

## Usage

```console
pip install -r requirements.txt
```

```console
python3 main.py --access_key ${ACCESS_KEY} --picollm_model_path ${PICOLLM_MODEL_PATH}
```

```console
python main.py --help
```

## Profiling

```console
python3 main.py --access_key ${ACCESS_KEY} --picollm_model_path ${PICOLLM_MODEL_PATH} --profile
```

20 changes: 10 additions & 10 deletions recipes/llm-voice-assistant/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ def main() -> None:
parser.add_argument(
'--picollm_model_path',
required=True,
help='Absolute path to the file containing LLM parameters.')
help='Absolute path to the file containing LLM parameters (`.pllm`).')
parser.add_argument(
'--keyword-model_path',
help='Absolute path to the keyword model file. If not set, `Picovoice` will be used as the wake phrase')
help='Absolute path to the keyword model file (`.ppn`). If not set, `Picovoice` will be the wake phrase')
parser.add_argument(
'--cheetah_endpoint_duration_sec',
type=float,
Expand Down Expand Up @@ -267,7 +267,7 @@ def main() -> None:

pllm = picollm.create(access_key=access_key, model_path=picollm_model_path, device=picollm_device)
dialog = pllm.get_dialog()
log.info(f"→ picoLLM V{pllm.version} {pllm.model}")
log.info(f"→ picoLLM V{pllm.version} <{pllm.model}>")

main_connection, orca_process_connection = Pipe()
orca_process = Process(target=orca_worker, args=(access_key, orca_process_connection, orca_warmup_sec))
Expand All @@ -289,7 +289,7 @@ def handler(_, __) -> None:
signal.signal(signal.SIGINT, handler)

wake_word_detected = False
human_request = ''
user_request = ''
endpoint_reached = False
utterance_end_sec = 0

Expand All @@ -308,24 +308,24 @@ def handler(_, __) -> None:
if wake_word_detected:
log.debug(f"[Porcupine RTF: {porcupine_profiler.rtf():.3f}]")
log.info("$ Wake word detected, utter your request or question ...\n")
log.info("human > ", end='')
log.info("User > ", end='')
elif not endpoint_reached:
pcm = mic.read()
cheetah_profiler.tick()
partial_transcript, endpoint_reached = cheetah.process(pcm)
cheetah_profiler.tock(pcm)
log.info(partial_transcript, end='')
human_request += partial_transcript
user_request += partial_transcript
if endpoint_reached:
utterance_end_sec = time.time()
cheetah_profiler.tick()
remaining_transcript = cheetah.flush()
cheetah_profiler.tock()
human_request += remaining_transcript
user_request += remaining_transcript
log.info(remaining_transcript, end='\n\n')
log.debug(f"[Cheetah RTF: {cheetah_profiler.rtf():.3f}]")
else:
dialog.add_human_request(human_request)
dialog.add_human_request(user_request)

picollm_profiler = TPSProfiler()

Expand All @@ -335,7 +335,7 @@ def llm_callback(text: str) -> None:
{'command': 'synthesize', 'text': text, 'utterance_end_sec': utterance_end_sec})
log.info(text, end='')

log.info("\nllm > ", end='')
log.info("\nLLM > ", end='')
res = pllm.generate(
prompt=dialog.prompt(),
completion_token_limit=picollm_completion_token_limit,
Expand All @@ -359,7 +359,7 @@ def llm_callback(text: str) -> None:
assert main_connection.recv()['done']

wake_word_detected = False
human_request = ''
user_request = ''
endpoint_reached = False
log.info("\n$ Say `Picovoice` ...")
finally:
Expand Down

0 comments on commit bef7789

Please sign in to comment.