add fish speech tts
This commit is contained in:
@@ -311,6 +311,49 @@ export async function sayTTS(character:character,text:string) {
|
||||
throw new Error(text);
|
||||
}
|
||||
}
|
||||
case 'fishspeech':{
|
||||
if (character.fishSpeechConfig.model._id === ''){
|
||||
throw new Error('FishSpeech Model is not selected')
|
||||
}
|
||||
const audioContext = new AudioContext();
|
||||
|
||||
const body = {
|
||||
text: text,
|
||||
reference_id: character.fishSpeechConfig.model._id,
|
||||
chunk_length: character.fishSpeechConfig.chunk_length,
|
||||
normalize: character.fishSpeechConfig.normalize,
|
||||
format: 'mp3',
|
||||
mp3_bitrate: 192,
|
||||
}
|
||||
|
||||
|
||||
console.log(body)
|
||||
|
||||
const response = await globalFetch(`https://api.fish.audio/v1/tts`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${db.fishSpeechKey}`
|
||||
},
|
||||
body: body,
|
||||
rawResponse: true,
|
||||
})
|
||||
console.log(response)
|
||||
|
||||
if (response.ok) {
|
||||
const audioBuffer = response.data.buffer;
|
||||
audioContext.decodeAudioData(audioBuffer, (decodedData) => {
|
||||
const sourceNode = audioContext.createBufferSource();
|
||||
sourceNode.buffer = decodedData;
|
||||
sourceNode.connect(audioContext.destination);
|
||||
sourceNode.start();
|
||||
});
|
||||
} else {
|
||||
const textBuffer: Uint8Array = response.data.buffer
|
||||
const text = Buffer.from(textBuffer).toString('utf-8')
|
||||
throw new Error(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
alertError(`TTS Error: ${error}`)
|
||||
|
||||
Reference in New Issue
Block a user