Repository navigation
Add HandyVoiceParser to delegate voice input to @cjpais/Handy - #6
Conversation
Co-authored-by: tathagata <68151+tathagata@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Introduces a new HandyVoiceParser implementation that integrates with the external handy CLI + clipboard to provide the same speech_to_text() interface as the existing VoiceParser, enabling it to be used as a drop-in parser in the orchestration flow.
Changes:
- Added
HandyVoiceParserto trigger Handy transcription via subprocess and retrieve transcripts by polling the clipboard. - Added unit tests covering
HandyVoiceParsertrigger, clipboard polling, andspeech_to_text()behavior. - Added
pyperclipdependency for cross-platform clipboard access.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/voice_parser.py |
Adds HandyVoiceParser implementation (subprocess trigger + clipboard polling + sanitization). |
tests/test_voice_parser.py |
Adds test suite for HandyVoiceParser behavior and error cases. |
requirements.txt |
Adds pyperclip dependency. |
Comments suppressed due to low confidence (2)
src/voice_parser.py:175
- The
speech_to_textdocstring says it "reuses :meth:VoiceParser.sanitizelogic", but the implementation duplicates the sanitization inline. This can drift over time (and currently produces different error messaging thanVoiceParser.sanitize). Consider callingVoiceParser.sanitizedirectly (e.g., by factoring sanitization into a shared helper/staticmethod) so both parsers stay consistent.
def speech_to_text(self):
"""Delegate voice capture to Handy and return the transcribed text.
Captures the current clipboard content, triggers Handy transcription,
waits for the clipboard to be updated with the transcript, sanitizes
the result, and returns it.
The sanitization step reuses :meth:`VoiceParser.sanitize` logic:
collapses internal whitespace and raises :class:`VoiceParserError` for
empty results.
"""
if self._pyperclip is None:
raise VoiceParserError(
"pyperclip is required for HandyVoiceParser. "
"Install it with: pip install pyperclip"
)
try:
previous = self._pyperclip.paste()
except Exception as e:
raise VoiceParserError(f"Failed to read clipboard: {e}") from e
self.trigger()
raw_text = self.wait_for_transcript(previous_clipboard=previous)
if not raw_text:
raise VoiceParserError("Handy returned an empty transcript.")
return re.sub(r"\s+", " ", raw_text.strip())
tests/test_voice_parser.py:2
- Unused import:
callis imported fromunittest.mockbut not used anywhere in this test module. Removing it will keep the tests tidy and avoid future lint noise if a linter is added to CI.
from unittest.mock import MagicMock, patch, call
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| deadline = time.monotonic() + self._timeout | ||
| while time.monotonic() < deadline: | ||
| try: | ||
| current = self._pyperclip.paste() | ||
| except Exception as e: | ||
| raise VoiceParserError(f"Failed to read clipboard: {e}") from e | ||
| if current != previous_clipboard: | ||
| logger.info("Handy transcript received from clipboard.") | ||
| return current.strip() | ||
| time.sleep(self._poll_interval) |
There was a problem hiding this comment.
wait_for_transcript relies on current != previous_clipboard to detect completion. If the user speaks the same command as what's already on the clipboard (or Handy produces identical text), this will never be observed as a change and will time out even though transcription succeeded. Consider using a sentinel strategy (e.g., optionally write a unique marker / clear clipboard before triggering and optionally restore), or track changes via an additional signal rather than strict inequality with the previous clipboard contents.
@cjpais/Handydoesn't expose an HTTP API, but it does provide two integration points: a CLI flag (handy --toggle-transcription) to control recording, and clipboard output (Handy pastes the transcript into the active text field when done). This PR wires those together into aHandyVoiceParserthat satisfies the samespeech_to_text()contract as the existingVoiceParser, making it a drop-in replacement inOrchestrator.New:
HandyVoiceParser(src/voice_parser.py)trigger()— runshandy --toggle-transcriptionvia subprocess; raisesVoiceParserErrorif the executable is missing or exits non-zerowait_for_transcript(previous_clipboard)— polls the clipboard viapyperclipuntil the content changes (Handy pasted the result), with a configurable timeoutspeech_to_text()— composes the above: snapshot clipboard → trigger Handy → wait → sanitize → returnDependencies
pypercliptorequirements.txtfor cross-platform clipboard access.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.