@aituber-onair/core
Version:
Core library for AITuber OnAir providing voice synthesis and chat processing
35 lines • 1.15 kB
JavaScript
import { OPENAI_TTS_API_URL } from '../../../constants';
/**
* OpenAI TTS voice synthesis engine
*/
export class OpenAiEngine {
async fetchAudio(input, speaker, apiKey) {
if (!apiKey) {
throw new Error('OpenAI API key is required');
}
const talk = input;
const text = talk.message.trim();
const response = await fetch(OPENAI_TTS_API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({
model: 'tts-1',
voice: speaker,
input: text,
}),
});
if (!response.ok) {
console.error('Failed to fetch TTS from OpenAI TTS:', response.status);
throw new Error('Failed to fetch TTS from OpenAI TTS.');
}
const blob = await response.blob();
return await blob.arrayBuffer();
}
getTestMessage(textVoiceText) {
return textVoiceText || 'OpenAI TTSを使用します';
}
}
//# sourceMappingURL=OpenAiEngine.js.map