-
Notifications
You must be signed in to change notification settings - Fork 19
feat: add model-aware voice input with audio support detection #621
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
Draft
MarvelNwachukwu
wants to merge
3
commits into
main
Choose a base branch
from
agent-skills-impl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@iqai/adk": patch | ||
| --- | ||
|
|
||
| feat: add model-aware voice input with audio support detection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,8 +3,33 @@ import { | |||||||||||||||||||||
| isSpeechRecognitionSupported, | ||||||||||||||||||||||
| startTranscription, | ||||||||||||||||||||||
| } from "@/lib/transcribe-audio"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const useVoiceRecording = () => { | ||||||||||||||||||||||
| import { supportsAudioInput } from "@/lib/model-capabilities"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| interface UseVoiceRecordingOptions { | ||||||||||||||||||||||
| modelName?: string | null; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Validates if transcribed text has meaningful content | ||||||||||||||||||||||
| * Checks for minimum length and non-placeholder text | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| function isValidTranscript(text: string): boolean { | ||||||||||||||||||||||
| const trimmed = text.trim(); | ||||||||||||||||||||||
| // Minimum 3 characters to be considered valid | ||||||||||||||||||||||
| if (trimmed.length < 3) return false; | ||||||||||||||||||||||
| // Check if it's not just placeholder text | ||||||||||||||||||||||
| const placeholders = [ | ||||||||||||||||||||||
| "voice message", | ||||||||||||||||||||||
| "transcription unavailable", | ||||||||||||||||||||||
| "listening", | ||||||||||||||||||||||
| "recording", | ||||||||||||||||||||||
| ]; | ||||||||||||||||||||||
| const lower = trimmed.toLowerCase(); | ||||||||||||||||||||||
| return !placeholders.some((placeholder) => lower === placeholder); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const useVoiceRecording = (options?: UseVoiceRecordingOptions) => { | ||||||||||||||||||||||
| const { modelName } = options || {}; | ||||||||||||||||||||||
| const [recording, setRecording] = useState(false); | ||||||||||||||||||||||
| const [audioFile, setAudioFile] = useState<File | null>(null); | ||||||||||||||||||||||
| const [error, setError] = useState<string | null>(null); | ||||||||||||||||||||||
|
|
@@ -16,7 +41,18 @@ const useVoiceRecording = () => { | |||||||||||||||||||||
| const stopTranscriptionRef = useRef<(() => void) | null>(null); | ||||||||||||||||||||||
| const accumulatedTranscriptRef = useRef<string>(""); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Check if model supports audio | ||||||||||||||||||||||
| const audioSupported = supportsAudioInput(modelName); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const startRecording = useCallback(async () => { | ||||||||||||||||||||||
| // Check if model supports audio | ||||||||||||||||||||||
| if (!audioSupported) { | ||||||||||||||||||||||
| setError( | ||||||||||||||||||||||
| "Voice input is not supported for this model. Please use GPT-4o or Gemini models.", | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
| return; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| setError(null); | ||||||||||||||||||||||
| setAudioFile(null); | ||||||||||||||||||||||
|
|
@@ -96,11 +132,12 @@ const useVoiceRecording = () => { | |||||||||||||||||||||
| setError(errorMessage); | ||||||||||||||||||||||
| console.error("Error starting recording:", err); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| }, []); | ||||||||||||||||||||||
| }, [audioSupported]); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const stopRecording = useCallback(async (): Promise<{ | ||||||||||||||||||||||
| file: File | null; | ||||||||||||||||||||||
| transcript: string; | ||||||||||||||||||||||
| hasValidTranscript: boolean; | ||||||||||||||||||||||
| }> => { | ||||||||||||||||||||||
| return new Promise((resolve) => { | ||||||||||||||||||||||
| // Step 1: Stop transcription first | ||||||||||||||||||||||
|
|
@@ -113,10 +150,15 @@ const useVoiceRecording = () => { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Step 2: Get the final transcribed text | ||||||||||||||||||||||
| const finalTranscript = accumulatedTranscriptRef.current.trim(); | ||||||||||||||||||||||
| const hasValidTranscript = isValidTranscript(finalTranscript); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (!mediaRecorderRef.current) { | ||||||||||||||||||||||
| setRecording(false); | ||||||||||||||||||||||
| resolve({ file: null, transcript: finalTranscript }); | ||||||||||||||||||||||
| resolve({ | ||||||||||||||||||||||
| file: null, | ||||||||||||||||||||||
| transcript: finalTranscript, | ||||||||||||||||||||||
| hasValidTranscript, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| return; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -143,20 +185,30 @@ const useVoiceRecording = () => { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Clean up microphone stream | ||||||||||||||||||||||
| if (streamRef.current) { | ||||||||||||||||||||||
| streamRef.current.getTracks().forEach((track) => track.stop()); | ||||||||||||||||||||||
| streamRef.current.getTracks().forEach((track) => { | ||||||||||||||||||||||
| track.stop(); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| streamRef.current = null; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| mediaRecorderRef.current = null; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Return both the file and the transcript | ||||||||||||||||||||||
| resolve({ file, transcript: finalTranscript }); | ||||||||||||||||||||||
| resolve({ | ||||||||||||||||||||||
| file, | ||||||||||||||||||||||
| transcript: finalTranscript, | ||||||||||||||||||||||
| hasValidTranscript, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
Comment on lines
+196
to
+200
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (mediaRecorderRef.current.state !== "inactive") { | ||||||||||||||||||||||
| mediaRecorderRef.current.stop(); | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| setRecording(false); | ||||||||||||||||||||||
| resolve({ file: null, transcript: finalTranscript }); | ||||||||||||||||||||||
| resolve({ | ||||||||||||||||||||||
| file: null, | ||||||||||||||||||||||
| transcript: finalTranscript, | ||||||||||||||||||||||
| hasValidTranscript, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| }, []); | ||||||||||||||||||||||
|
|
@@ -177,6 +229,7 @@ const useVoiceRecording = () => { | |||||||||||||||||||||
| startRecording, | ||||||||||||||||||||||
| stopRecording, | ||||||||||||||||||||||
| clearAudio, | ||||||||||||||||||||||
| audioSupported, | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
onClickhandler on this disabledPromptInputMicButtonwill not be triggered by user clicks because the button'sdisabledprop is set totrue. Thetoast.errorwill never be shown. The tooltip already provides sufficient information to the user about why the button is disabled. ThisonClickhandler is effectively dead code and should be removed for clarity.