style.transition = 'height 0.1s ease';
container.appendChild(bar);
}
}

// 创建频谱显示
createSpectrum() {
const container = document.getElementById('spectrum');
// 创建频谱可视化
for (let i = 0; i < 64; i++) {
const bar = document.createElement('div');
bar.style.position = 'absolute';
bar.style.bottom = '0';
bar.style.left = `${(i / 64) * 100}%`;
bar.style.width = '3px';
bar.style.height = '0px';
bar.style.background = 'linear-gradient(to top, #f093fb, #f5576c)';
bar.style.borderRadius = '2px 2px 0 0';
bar.style.transition = 'height 0.05s ease';
container.appendChild(bar);
}
}

// 创建时间线
createTimeline() {
const container = document.getElementById('timeline');
// 创建时间线标记
for (let i = 0; i < 10; i++) {
const marker = document.createElement('div');
marker.style.position = 'absolute';
marker.style.bottom = '0';
marker.style.left = `${i * 10}%`;
marker.style.width = '1px';
marker.style.height = '20px';
marker.style.background = '#667eea';

const label = document.createElement('div');
label.style.position = 'absolute';
label.style.bottom = '25px';
label.style.left = `${i * 10}%`;
label.style.transform = 'translateX(-50%)';
label.style.fontSize = '10px';
label.style.color = '#667eea';
label.textContent = `${i * 10}s`;

container.appendChild(marker);
container.appendChild(label);
}
}

// 更新进度
updateProgress() {
const progress = (this.currentTime / this.totalTime) * 100;
document.getElementById('progress').style.width = `${progress}%`;
document.getElementById('current-time').textContent = this.formatTime(this.currentTime);
}

// 格式化时间
formatTime(seconds) {
const mins = Math.floor(seconds / 60);
const secs = Math.floor(seconds % 60);
return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
}

// 切换录制
toggleRecord() {
this.isRecording = !this.isRecording;
const recordBtn = document.getElementById('record-btn');

if (this.isRecording) {
recordBtn.style.background = '#f56565';
recordBtn.textContent = '⏹️ 停止录制';
this.recordedData = [];
this.showMessage('开始录制...');
} else {
recordBtn.style.background = '';
recordBtn.textContent = '⏺️ 录制';
this.showMessage(`录制完成,共 ${this.recordedData.length} 个音频片段`);
this.saveRecording();
}
}

// 保存录制
saveRecording() {
const recording = {
timestamp: new Date().toISOString(),
duration: this.currentTime,
sections: this.sections,
voice: this.currentVoice,
instrument: this.currentInstrument,
bpm: this.bpm,
emotionProfile: this.emotionProfile,
audioData: this.recordedData
};

// 保存到localStorage
const recordings = JSON.parse(localStorage.getItem('ttsRecordings') || '[]');
recordings.push(recording);
localStorage.setItem('ttsRecordings', JSON.stringify(recordings));

this.showMessage('录制已保存到本地存储');
}

// 显示消息
showMessage(message) {
console.log(`💬 ${message}`);
// 可以在这里添加UI消息显示
const status = document.getElementById('current-section');
const originalText = status.textContent;
status.textContent = `[${message}]`;

setTimeout(() => {
status.textContent = originalText;
}, 3000);
}
}

// 🎵 汉字发音数据库
class ChinesePronunciationDB {
constructor() {
this.pronunciations = new Map();
this.initDatabase();
}

// 初始化汉字发音数据库
initDatabase() {
// 基础汉字发音映射(简化版)
const basicPronunciations = {
'啊': { pinyin: 'a', tone: 1, frequency: 440 },
'哦': { pinyin: 'o', tone: 2, frequency: 392 },
'呃': { pinyin: 'e', tone: 4, frequency: 349 },
'一': { pinyin: 'yi', tone: 1, frequency: 523 },
'乌': { pinyin: 'wu', tone: 1, frequency: 294 },
'波': { pinyin: 'bo', tone: 1, frequency: 220 },
'得': { pinyin: 'de', tone: 2, frequency: 247 },
'哥': { pinyin: 'ge', tone: 1, frequency: 165 },
'科': { pinyin: 'ke', tone: 1, frequency: 185 },
'喝': { pinyin: 'he', tone: 1, frequency: 208 },
'机': { pinyin: 'ji', tone: 1, frequency: 262 },
'七': { pinyin: 'qi', tone: 1, frequency: 294 },
'西': { pinyin: 'xi', tone: 1, frequency: 330 },
'知': { pinyin: 'zhi', tone: 1, frequency: 175 },
'吃': { pinyin: 'chi', tone: 1, frequency: 196 },
'诗': { pinyin: 'shi', tone: 1, frequency: 220 },
'日': { pinyin: 'ri', tone: 4, frequency: 165 },
'资': { pinyin: 'zi', tone: 1, frequency: 147 },
'雌': { pinyin: 'ci', tone: 2, frequency: 165 },
'思': { pinyin: 'si', tone: 1, frequency: 185 }
};

// 添加到Map
Object.entries(basicPronunciations).forEach(([char, data]) => {
this.pronunciations.set(char, data);
});
}

// 获取汉字发音
getPronunciation(char) {
return this.pronunciations.get(char) || { pinyin: 'unknown', tone: 1, frequency: 440 };
}

// 添加自定义发音
addPronunciation(char, pinyin, tone, frequency) {
this.pronunciations.set(char, { pinyin, tone, frequency });
}
}

// 🚀 初始化系统
document.addEventListener('DOMContentLoaded', function() {
window.ttsSystem = new ProfessionalTTS();
window.pronunciationDB = new ChinesePronunciationDB();

console.log('🎵 专业级语音合成系统已初始化');
console.log('💡 功能包括:');
console.log(' - 多发音人选择(男女声、童声)');
console.log(' - 多乐器伴奏');

Prev | Next
Pg.: 1 ... 3 4 5 6 7 8 9 10 11 12 13 ... 56


Back to home | File page

Subscribe | Register | Login | N