voice
This commit is contained in:
parent
bdc7d80216
commit
7df70be593
1 changed files with 9 additions and 3 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue