@aituber-onair/voice
Version:
Voice synthesis library for AITuber OnAir
47 lines (46 loc) • 1.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.textsToScreenplay = exports.splitSentence = void 0;
const emotionParser_1 = require("../utils/emotionParser");
const splitSentence = (text) => {
const splitMessages = text.split(/(?<=[。.!?\n])/g);
return splitMessages.filter((msg) => msg !== '');
};
exports.splitSentence = splitSentence;
const textsToScreenplay = (texts) => {
const screenplays = [];
let prevExpression = 'neutral';
for (let i = 0; i < texts.length; i++) {
const text = texts[i];
const { emotion, cleanText } = emotionParser_1.EmotionParser.extractEmotion(text);
const tag = emotion || prevExpression;
let expression = prevExpression;
if (emotionParser_1.EmotionParser.isValidEmotion(tag)) {
expression = tag;
prevExpression = tag;
}
screenplays.push({
expression: expression,
talk: {
style: emotionToTalkStyle(expression),
message: cleanText,
},
});
}
return screenplays;
};
exports.textsToScreenplay = textsToScreenplay;
const emotionToTalkStyle = (emotion) => {
switch (emotion) {
case 'angry':
return 'angry';
case 'happy':
return 'happy';
case 'sad':
return 'sad';
case 'surprised':
return 'surprised';
default:
return 'talk';
}
};