const lyrics = document.getElementById('lyrics-editor').value;
this.systemState.sections = this.parseLyrics(lyrics);
if (this.systemState.sections.length === 0) {
this.showMessage('没有检测到有效的歌曲段落', 'warning');
this.stopPlayback();
return;
}
this.systemState.totalTime = this.calculateTotalDuration();
this.systemState.currentTime = 0;
this.systemState.currentSectionIndex = 0;
this.systemState.startTime = Date.now();
this.updateProgressUI();
this.startPlaybackLoop();
await this.playCurrentSection();
} catch (error) {
this.handleSystemError('播放失败', error);
}
}
pausePlayback() {
this.systemState.isPlaying = false;
this.updatePlaybackUI();
if (this.systemState.animationFrame) {
cancelAnimationFrame(this.systemState.animationFrame);
}
}
stopPlayback() {
this.systemState.isPlaying = false;
this.systemState.currentTime = 0;
this.systemState.currentSectionIndex = 0;
this.updatePlaybackUI();
if (this.systemState.animationFrame) {
cancelAnimationFrame(this.systemState.animationFrame);
}
this.updateProgressUI();
this.showMessage('播放已停止', 'info');
}
// 播放循环
startPlaybackLoop() {
const updatePlayback = () => {
if (!this.systemState.isPlaying) return;
const elapsed = (Date.now() - this.systemState.startTime) / 1000;
this.systemState.currentTime = Math.min(elapsed, this.systemState.totalTime);
this.updateProgressUI();
this.updateVisualizations();
if (this.systemState.currentTime >= this.systemState.totalTime) {
if (this.systemState.isLooping) {
this.systemState.currentTime = 0;
this.systemState.startTime = Date.now();
this.systemState.currentSectionIndex = 0;
this.playCurrentSection();
} else {
this.stopPlayback();
}
}
this.systemState.animationFrame = requestAnimationFrame(updatePlayback);
};
this.systemState.animationFrame = requestAnimationFrame(updatePlayback);
}
// 播放当前段落
async playCurrentSection() {
if (!this.systemState.isPlaying ||
this.systemState.currentSectionIndex >= this.systemState.sections.length) {
return;
}
const section = this.systemState.sections[this.systemState.currentSectionIndex];
this.updateCurrentSectionUI(section.name);
if (section.type === 'interlude') {
await this.playInterlude(section);
} else {
await this.playSingingSection(section);
}
this.systemState.currentSectionIndex++;
if (this.systemState.isPlaying) {
await this.playCurrentSection();
}
}
// 播放间奏
async playInterlude(section) {
const duration = this.calculateInterludeDuration(section);
await this.generateInstrumentalMusic(this.musicSystem.currentInstrument, duration, 'interlude');
await this.delay(duration * 1000);
}
// 播放演唱段落
async playSingingSection(section) {
for (const line of section.lyrics) {
if (!this.systemState.isPlaying) break;
const emotionScores = this.analyzeTextEmotion(line);
await this.synthesizeAdvancedSpeech(line, this.musicSystem.currentVoice, emotionScores);
await this.addIntelligentAccompaniment(line, section.type);
await this.delay(200);
}
}
// 高级语音合成
async synthesizeAdvancedSpeech(text, voiceType, emotionScores) {
return new Promise((resolve) => {
if ('speechSynthesis' in window) {
const utterance = new SpeechSynthesisUtterance(text);
this.configureAdvancedVoice(utterance, voiceType, emotionScores);
utterance.onend = () => resolve();
utterance.onerror = () => resolve();
window.speechSynthesis.speak(utterance);
} else {
this.generateSyntheticSpeech(text, voiceType, emotionScores).then(resolve);
}
});
}
// 配置高级语音
configureAdvancedVoice(utterance, voiceType, emotionScores) {
const voiceConfig = this.getVoiceConfiguration(voiceType);
const emotionalConfig = this.applyEmotionalAdjustments(voiceConfig, emotionScores);
Object.assign(utterance, emotionalConfig);
// 选择系统语音
if (this.availableVoices) {
const suitableVoices = this.findSuitableVoices(voiceType);
if (suitableVoices.length > 0) {
utterance.voice = suitableVoices[0];
}
}
}
// 获取语音配置
getVoiceConfiguration(voiceType) {
const configurations = {
female1: { pitch: 1.2, rate: 0.9, volume: 1.0 },
female2: { pitch: 1.3, rate: 1.1, volume: 0.9 },
male1: { pitch: 0.8, rate: 0.8, volume: 1.0 },
male2: { pitch: 0.7, rate: 1.0, volume: 1.1 },
child: { pitch: 1.5, rate: 1.2, volume: 0.8 }
};
return configurations[voiceType] || configurations.female1;
}
// 应用情感调整
applyEmotionalAdjustments(config, emotionScores) {
const adjusted = { ...config };
const happiness = emotionScores.happiness / 100;
const sadness = emotionScores.sadness / 100;
const anger = emotionScores.anger / 100;
// 情感影响算法
adjusted.pitch += (happiness - 0.5) * 0.3;
adjusted.rate += (anger - 0.
Back to home |
File page
Subscribe |
Register |
Login
| N