Skip to content

Commit

Permalink
Merge branch 'feature/ignore-tts-hallucinations'
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Braiden committed May 1, 2024
2 parents 9d23882 + 0619c88 commit ec784e2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion glados.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@

LLAMA_SERVER_HEADERS = {"Authorization": "Bearer your_api_key_here"}
LLAMA3_TEMPLATE = "{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{% if add_generation_prompt %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}{% endif %}"
STT_HALLUCINATIONS = set((
"You",
"you're",
"Thank you.",
))

AI_OUTPUT_TO_IGNORE = set((
"imend",
Expand Down Expand Up @@ -299,8 +304,9 @@ def _process_detected_audio(self):
self.input_stream.stop()

detected_text = self.asr(self.samples)
hallucination = detected_text and any(hallucination.lower() == detected_text.lower() for hallucination in STT_HALLUCINATIONS)

if detected_text:
if detected_text and not hallucination:
logger.success(f"ASR text: '{detected_text}'")

if self.wake_word is not None:
Expand All @@ -315,6 +321,13 @@ def _process_detected_audio(self):
self.llm_queue.put(detected_text)
self.processing = True

elif hallucination:
logger.success(f"ASR text: '{detected_text}' (NOTE: ignored, as a probable hallucination from the TTS model)")
self.processing = True
else:
logger.info("Heard audio, but didn't detect any speech within it.")
self.processing = True

self.reset()
self.input_stream.start()

Expand Down

0 comments on commit ec784e2

Please sign in to comment.