WellNuo/hooks/useTTS.ts
Sergei d453126c89 feat: Room location picker + robster credentials
- Backend: Update Legacy API credentials to robster/rob2
- Frontend: ROOM_LOCATIONS with icons and legacyCode mapping
- Device Settings: Modal picker for room selection
- api.ts: Bidirectional conversion (code ↔ name)
- Various UI/UX improvements across screens

PRD-DEPLOYMENT.md completed (Score: 9/10)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-24 15:22:40 -08:00

59 lines
1.2 KiB
TypeScript

import { useState, useEffect, useCallback } from 'react';
import {
initializeSherpaTTS,
speak,
stop,
isAvailable,
addStateListener,
getState,
type PiperVoice,
} from '@/services/sherpaTTS';
interface TTSState {
initialized: boolean;
initializing: boolean;
error: string | null;
isSpeaking: boolean;
}
export function useTTS() {
const [state, setState] = useState<TTSState>({
...getState(),
isSpeaking: false,
});
useEffect(() => {
const unsubscribe = addStateListener((newState) => {
setState((prev) => ({
...prev,
...newState,
}));
});
// In Expo Go mode, don't try to initialize (stub always returns false)
// This is handled by the stub in sherpaTTS.ts
return unsubscribe;
}, []);
const speakText = useCallback(
async (text: string, options?: { speed?: number; speakerId?: number }) => {
// Always return false in Expo Go mode - voice.tsx will use expo-speech instead
return;
},
[]
);
const stopSpeaking = useCallback(() => {
stop();
setState((prev) => ({ ...prev, isSpeaking: false }));
}, []);
return {
...state,
isReady: false, // Always false in Expo Go mode
speak: speakText,
stop: stopSpeaking,
};
}