@aituber-onair/core
Version:
Core library for AITuber OnAir providing voice synthesis and chat processing
41 lines • 1.24 kB
JavaScript
import { emotions } from '../../types';
export const splitSentence = (text) => {
const splitMessages = text.split(/(?<=[。.!?\n])/g);
return splitMessages.filter((msg) => msg !== '');
};
export const textsToScreenplay = (texts) => {
const screenplays = [];
let prevExpression = 'neutral';
for (let i = 0; i < texts.length; i++) {
const text = texts[i];
const match = text.match(/\[(.*?)\]/);
const tag = (match && match[1]) || prevExpression;
const message = text.replace(/\[(.*?)\]/g, '');
let expression = prevExpression;
if (emotions.includes(tag)) {
expression = tag;
prevExpression = tag;
}
screenplays.push({
expression: expression,
talk: {
style: emotionToTalkStyle(expression),
message: message,
},
});
}
return screenplays;
};
const emotionToTalkStyle = (emotion) => {
switch (emotion) {
case 'angry':
return 'angry';
case 'happy':
return 'happy';
case 'sad':
return 'sad';
default:
return 'talk';
}
};
//# sourceMappingURL=messages.js.map