@aituber-onair/voice
Version:
Voice synthesis library for AITuber OnAir
36 lines (35 loc) • 1.05 kB
JavaScript
import { EmotionParser } from './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
*/
export function textToScreenplay(text) {
const { emotion, cleanText } = 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
*/
export 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)
*/
export function screenplayToText(screenplay) {
if (screenplay.emotion) {
return EmotionParser.addEmotionTag(screenplay.emotion, screenplay.text);
}
return screenplay.text;
}