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
|
* Generate speech from text
|
||||||
* @param {string} text - Text to speak
|
* @param {string} text - Text to speak
|
||||||
* @param {Object} options - Options
|
* @param {Object} options - Options
|
||||||
|
* @param {string} options.voice - Voice ID (optional)
|
||||||
* @returns {Promise<string>} Audio URL
|
* @returns {Promise<string>} Audio URL
|
||||||
*/
|
*/
|
||||||
const generateSpeech = useCallback(async (text, options = {}) => {
|
const generateSpeech = useCallback(async (text, options = {}) => {
|
||||||
const { cache = true } = options;
|
const { cache = true, voice } = options;
|
||||||
|
|
||||||
// Check cache first
|
// Check cache first
|
||||||
const cacheKey = `${text}_${voice}`;
|
const cacheKey = text;
|
||||||
if (cache && audioCache.current.has(cacheKey)) {
|
if (cache && audioCache.current.has(cacheKey)) {
|
||||||
return audioCache.current.get(cacheKey);
|
return audioCache.current.get(cacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const requestBody = { text };
|
||||||
|
if (voice) {
|
||||||
|
requestBody.voice = voice;
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(`${API_URL}/voice/tts`, {
|
const response = await fetch(`${API_URL}/voice/tts`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
body: JSON.stringify({ text, voice }),
|
body: JSON.stringify(requestBody),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue