@aituber-onair/voice
Version:
Voice synthesis library for AITuber OnAir
39 lines (38 loc) • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpenAiEngine = void 0;
const voiceEngine_1 = require("../constants/voiceEngine");
/**
* OpenAI TTS voice synthesis engine
*/
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(voiceEngine_1.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を使用します';
}
}
exports.OpenAiEngine = OpenAiEngine;