flat: 优化语音

This commit is contained in:
史典卓
2025-04-16 14:24:06 +08:00
parent 0d2b8ae65f
commit 446b48ef6d
28 changed files with 1059 additions and 264 deletions

View File

@@ -102,43 +102,36 @@ const initWaveBars = () => {
// 更新波形显示
const updateWaveform = () => {
if (!props.isActive) return;
// 如果没有传入音频数据,则使用模拟数据
const AMPLIFY = 1.6; // 振幅放大
const center = centerIndex.value;
// 如果没有传入音频数据,则使用模拟数据(加强振幅)
const audioData =
props.audioData.length > 0
? props.audioData
: Array(centerIndex.value + 1)
? props.audioData.map((v) => Math.min(v * AMPLIFY, 1))
: Array(center + 1)
.fill(0)
.map(() => Math.random() * 0.5 + 0.2);
// 从中间向两侧处理
for (let i = 0; i <= centerIndex.value; i++) {
// 左侧条索引
const leftIndex = centerIndex.value - i;
// 右侧条索引
const rightIndex = centerIndex.value + i;
.map(() => Math.random() * 0.7 + 0.3); // 模拟值更明显
// 获取音频数据值 (归一化到0-1)
for (let i = 0; i <= center; i++) {
const leftIndex = center - i;
const rightIndex = center + i;
const value = audioData[i] || 0;
// 更新左侧条
if (leftIndex >= 0) {
updateWaveBar(leftIndex, value);
}
// 更新右侧条(避免重复更新中心条)
if (leftIndex >= 0) updateWaveBar(leftIndex, value);
if (rightIndex < waveBars.value.length && rightIndex !== leftIndex) {
updateWaveBar(rightIndex, value);
}
}
// 继续动画
animationId = requestAnimationFrame(updateWaveform);
};
// 更新单个波形条
const updateWaveBar = (index, value) => {
// 动态高度 (4rpx到200rpx之间)
const height = 2 + value * 98;
// 动态高度 (4rpx到42rpx之间)
const height = 2 + value * 38;
// // 动态颜色
// let color;
// if (props.isCanceling) {