@aituber-onair/voice
Version:
Voice synthesis library for AITuber OnAir
41 lines (40 loc) • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.textToScreenplay = textToScreenplay;
exports.textsToScreenplay = textsToScreenplay;
exports.screenplayToText = screenplayToText;
const emotionParser_1 = require("./emotionParser");
/**
* Convert text to screenplay (text with emotion)
* @param text Original text (may contain emotion expressions like [happy])
* @returns Screenplay object with emotion and text separated
*/
function textToScreenplay(text) {
const { emotion, cleanText } = emotionParser_1.EmotionParser.extractEmotion(text);
if (emotion) {
return {
emotion,
text: cleanText,
};
}
return { text: cleanText };
}
/**
* Convert multiple texts to screenplay array
* @param texts Text array
* @returns Array of screenplay objects
*/
function textsToScreenplay(texts) {
return texts.map((text) => textToScreenplay(text));
}
/**
* Convert screenplay to text with emotion
* @param screenplay Screenplay object
* @returns Text with emotion (e.g. [happy] Hello)
*/
function screenplayToText(screenplay) {
if (screenplay.emotion) {
return emotionParser_1.EmotionParser.addEmotionTag(screenplay.emotion, screenplay.text);
}
return screenplay.text;
}