diff --git a/src/hooks/useVoice.js b/src/hooks/useVoice.js index e40f9b7..14cb7d2 100644 --- a/src/hooks/useVoice.js +++ b/src/hooks/useVoice.js @@ -44,25 +44,31 @@ export function useVoice() { * Generate speech from text * @param {string} text - Text to speak * @param {Object} options - Options + * @param {string} options.voice - Voice ID (optional) * @returns {Promise} Audio URL */ const generateSpeech = useCallback(async (text, options = {}) => { - const { cache = true } = options; + const { cache = true, voice } = options; // Check cache first - const cacheKey = `${text}_${voice}`; + const cacheKey = text; if (cache && audioCache.current.has(cacheKey)) { return audioCache.current.get(cacheKey); } try { + const requestBody = { text }; + if (voice) { + requestBody.voice = voice; + } + const response = await fetch(`${API_URL}/voice/tts`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, credentials: 'include', - body: JSON.stringify({ text, voice }), + body: JSON.stringify(requestBody), }); if (!response.ok) {