This commit is contained in:
Dmitry 2026-01-05 05:25:35 +03:00
parent bdc7d80216
commit 7df70be593

View file

@ -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<string>} 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) {