Repository navigation
feat: implement STT and TTS foundation using Expo libraries #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6fe03ac
implement stt and tts foundation using expo libs
Debashich cbff46e
Update app.json
Debashich ed30ee9
fix: start STT 100ms after mic prompt TTS completes
Copilot 4d51e99
Update scripts/postinstall-fixes.js
Debashich 4bbd0bd
Update src/screens/HomeScreen.tsx
Debashich 779a8b9
Update src/services/speech/stt.ts
Debashich fca6f3e
Update src/services/speech/tts.ts
Debashich 2649799
Update src/hooks/useSTT.ts
Debashich 64eef58
Update src/services/speech/stt.ts
Debashich 5ca7707
fix: delay onboarding STT start until after prompt TTS completes
Copilot 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const ensureExpoModuleScriptsShim = () => { | ||
| const shimPath = path.join('node_modules', 'expo-module-scripts', 'tsconfig.base'); | ||
| if (!fs.existsSync(shimPath)) { | ||
| // Some installs may not include expo-module-scripts in node_modules, but | ||
| // expo-speech-recognition still expects this tsconfig path to resolve. | ||
| fs.mkdirSync(path.dirname(shimPath), { recursive: true }); | ||
| fs.writeFileSync(shimPath, '{\n "extends": "./tsconfig.base.json"\n}\n'); | ||
| } | ||
| }; | ||
|
|
||
| const patchExpoSpeechRecognitionTsconfig = () => { | ||
| const tsconfigPath = path.join('node_modules', 'expo-speech-recognition', 'tsconfig.json'); | ||
| if (!fs.existsSync(tsconfigPath)) { | ||
| return; | ||
| } | ||
|
|
||
| const raw = fs.readFileSync(tsconfigPath, 'utf8'); | ||
| const parsed = JSON.parse(raw); | ||
| let changed = false; | ||
|
|
||
| if (parsed.extends !== '../expo-module-scripts/tsconfig.base.json') { | ||
| parsed.extends = '../expo-module-scripts/tsconfig.base.json'; | ||
| changed = true; | ||
| } | ||
|
|
||
| parsed.compilerOptions = parsed.compilerOptions || {}; | ||
|
|
||
| if (parsed.compilerOptions.rootDir !== './src') { | ||
| parsed.compilerOptions.rootDir = './src'; | ||
| changed = true; | ||
| } | ||
|
|
||
| if (changed) { | ||
| fs.writeFileSync(tsconfigPath, `${JSON.stringify(parsed, null, 2)}\n`); | ||
| } | ||
| }; | ||
|
|
||
| ensureExpoModuleScriptsShim(); | ||
| patchExpoSpeechRecognitionTsconfig(); | ||
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,6 @@ | ||
| export const VOICE_CONFIG = { | ||
| language: 'en-US', | ||
| rate: 0.85, | ||
| pitch: 1.3, | ||
| volume: 1.0, | ||
| }; |
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,55 @@ | ||
| import { useEffect, useState, useCallback, useRef } from 'react'; | ||
| import { startVoice, stopVoice, destroyVoice } from '../services/speech/stt'; | ||
|
|
||
| export const useSTT = () => { | ||
| const [transcript, setTranscript] = useState(''); | ||
| const [isListening, setIsListening] = useState(false); | ||
| const isListeningRef = useRef(false); | ||
|
|
||
| const startListening = useCallback(async () => { | ||
| console.log('[Hook] 🎯 startListening called, isListeningRef:', isListeningRef.current); | ||
|
|
||
| if (isListeningRef.current) { | ||
| console.log('[Hook] ⚠️ Already listening, skipping'); | ||
| return; | ||
| } | ||
|
|
||
| console.log('[Hook] 📍 Setting listening state to true'); | ||
| setTranscript(''); | ||
| setIsListening(true); | ||
| isListeningRef.current = true; | ||
|
|
||
| await startVoice( | ||
| (text) => { | ||
| console.log('[Hook] 📨 Transcript received:', text); | ||
| setTranscript(text); | ||
| }, | ||
| () => { | ||
| console.log('[Hook] 🏁 onEnd callback triggered'); | ||
| setIsListening(false); | ||
| isListeningRef.current = false; | ||
| } | ||
| ); | ||
| }, []); | ||
|
|
||
| const stopListening = useCallback(async () => { | ||
| console.log('[Hook] ⏹️ stopListening called'); | ||
| await stopVoice(); | ||
|
Debashich marked this conversation as resolved.
|
||
| setIsListening(false); | ||
| isListeningRef.current = false; | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| return () => { | ||
| console.log('[Hook] 🧹 Cleanup: calling destroyVoice'); | ||
| destroyVoice(); | ||
| }; | ||
| }, []); | ||
|
|
||
| return { | ||
| transcript, | ||
| isListening, | ||
| startListening, | ||
| stopListening, | ||
| }; | ||
| }; | ||
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,25 @@ | ||
| import { useEffect, useCallback } from 'react'; | ||
| import { speakText, stopSpeech, initializeTTS } from '../services/speech/tts'; | ||
|
|
||
| export const useTTS = () => { | ||
| useEffect(() => { | ||
| console.log('[Hook] 🎯 Mounting useTTS hook'); | ||
| const init = async () => { | ||
| await initializeTTS(); | ||
| console.log('[Hook] ✅ TTS initialized on mount'); | ||
| }; | ||
| init(); | ||
| }, []); | ||
|
|
||
| const speak = useCallback((text: string, onDone?: () => void) => { | ||
| console.log('[Hook] 📣 speak() called with:', text); | ||
| speakText(text, onDone); | ||
| }, []); | ||
|
|
||
| const stop = useCallback(async () => { | ||
| console.log('[Hook] ⏹️ stop() called'); | ||
| stopSpeech(); | ||
| }, []); | ||
|
|
||
| return { speak, stop }; | ||
| }; |
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.
Uh oh!
There was an error while loading. Please reload this page.