Skip to content

Commit 7a1ebdf

Browse files
committed
chore: rework change of line height on sound
1 parent 5cd3392 commit 7a1ebdf

2 files changed

Lines changed: 39 additions & 83 deletions

File tree

Lines changed: 28 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,43 @@
1-
<template>
2-
<div
3-
class=" bg-white w-[0.2rem] rounded-sm transition-all duration-300 ease-in-out"
4-
:class="{
5-
'recordingAnimation1' : showAnimation,
6-
'h-2': !isRecording,
7-
'h-1': isRecording,
8-
}"
1+
<template>
2+
<div
3+
v-for="(height, index) in lineHeights"
4+
:key="index"
5+
class="bg-white w-[0.2rem] rounded-sm transition-all duration-100 ease-out"
6+
:style="{ height }"
97
/>
10-
<div
11-
class=" bg-white w-[0.2rem] rounded-sm transition-all duration-300 ease-in-out"
12-
:class="{
13-
'recordingAnimation2' : showAnimation,
14-
'h-4': !isRecording,
15-
'h-1': isRecording,
16-
}"
17-
/>
18-
<div
19-
class=" bg-white w-[0.2rem] rounded-sm transition-all duration-300 ease-in-out"
20-
:class="{
21-
'recordingAnimation3' : showAnimation,
22-
'h-3': !isRecording,
23-
'h-1': isRecording,
24-
}"
25-
/>
26-
<div
27-
class=" bg-white w-[0.2rem] rounded-sm transition-all duration-300 ease-in-out"
28-
:class="{
29-
'recordingAnimation4' : showAnimation,
30-
'h-2': !isRecording,
31-
'h-1': isRecording,
32-
}"
33-
/>
34-
<template v-if="isRecording">
35-
<div
36-
class=" bg-white w-[0.2rem] rounded-sm h-1 transition-all duration-300 ease-in-out"
37-
:class="{
38-
'recordingAnimation5' : showAnimation,
39-
}"
40-
/>
41-
<p class="text-white ml-2">End</p>
42-
</template>
8+
<p v-if="isRecording" class="text-white ml-2">End</p>
439
</template>
4410

45-
46-
4711
<script setup lang="ts">
12+
import { computed } from 'vue';
13+
14+
const IDLE_LINE_HEIGHTS = [0.5, 1, 0.75, 0.5];
15+
const RECORDING_LINE_WEIGHTS = [0.45, 1, 0.75, 0.9, 0.55];
16+
const MIN_RECORDING_HEIGHT = 0.25;
17+
const MAX_RECORDING_DELTA = 0.9;
4818
4919
const props = defineProps<{
5020
showAnimation: boolean;
5121
isRecording: boolean;
22+
amplitude: number;
5223
}>();
5324
54-
</script>
55-
56-
<style scoped lang="scss">
57-
.recordingAnimation1 {
58-
animation: recordingAnimation 1s infinite;
59-
height: 0.3rem;
60-
}
61-
62-
.recordingAnimation2 {
63-
animation: recordingAnimation 1s infinite;
64-
animation-delay: 0.2s;
65-
height: 0.5rem;
25+
const normalizedAmplitude = computed(() => {
26+
if (!props.isRecording || !props.showAnimation) {
27+
return 0;
6628
}
6729
68-
.recordingAnimation3 {
69-
animation: recordingAnimation 1s infinite;
70-
animation-delay: 0.4s;
71-
height: 0.4rem;
72-
}
73-
74-
.recordingAnimation4 {
75-
animation: recordingAnimation 1s infinite;
76-
animation-delay: 0.6s;
77-
height: 0.5rem;
78-
}
30+
return Math.min(Math.max(props.amplitude, 0), 1);
31+
});
7932
80-
.recordingAnimation5 {
81-
animation: recordingAnimation 1s infinite;
82-
animation-delay: 0.8s;
83-
height: 0.3rem;
33+
const lineHeights = computed(() => {
34+
if (!props.isRecording) {
35+
return IDLE_LINE_HEIGHTS.map((height) => `${height}rem`);
8436
}
8537
86-
@keyframes recordingAnimation {
87-
0% {
88-
transform: scaleY(1);
89-
}
90-
50% {
91-
transform: scaleY(2);
92-
}
93-
100% {
94-
transform: scaleY(1);
95-
}
96-
}
97-
</style>
38+
return RECORDING_LINE_WEIGHTS.map((weight) => {
39+
const height = MIN_RECORDING_HEIGHT + normalizedAmplitude.value * MAX_RECORDING_DELTA * weight;
40+
return `${height}rem`;
41+
});
42+
});
43+
</script>

custom/speech_recognition_frontend/MicrophoneButon.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
>
99
<div class="w-5 h-5 flex items-center justify-center">
1010
<div v-if="microphoneButtonMode === 'listen' || microphoneButtonMode === 'off'" class="flex justify-evenly items-center gap-[0.1rem]">
11-
<AudioLines :showAnimation="showAudioWavesAnimation" :isRecording="microphoneButtonMode === 'listen'" />
11+
<AudioLines
12+
:showAnimation="showAudioWavesAnimation"
13+
:isRecording="microphoneButtonMode === 'listen'"
14+
:amplitude="audioAmplitude"
15+
/>
1216
</div>
1317
<div v-else-if="microphoneButtonMode === 'generating'" class="flex items-center justify-center gap-2 text-white text-sm">
1418
<span class="w-3 h-3 bg-white rounded-sm" />
@@ -39,6 +43,7 @@ const { stopCurrentAudioPlayback } = agentAudio;
3943
const { agentAudioMode } = storeToRefs(agentAudio);
4044
const microphoneButtonMode = ref<'off' | 'calibrating' | 'listen' | 'transcribing' | 'generating'>('off');
4145
const showAudioWavesAnimation = ref(false);
46+
const audioAmplitude = ref(0);
4247
const hideAnimationDebounced = debounce(() => {
4348
showAudioWavesAnimation.value = false;
4449
}, 100);
@@ -101,12 +106,14 @@ async function onStartRecording() {
101106
function onStopRecording() {
102107
agentAudio.playBeep(600);
103108
stopUserMedia();
109+
audioAmplitude.value = 0;
104110
showAudioWavesAnimation.value = false;
105111
}
106112
107113
function resetAll() {
108114
stopGenerationAndAudio();
109115
microphoneButtonMode.value = 'off';
116+
audioAmplitude.value = 0;
110117
showAudioWavesAnimation.value = false;
111118
hideAnimationDebounced.cancel();
112119
sendUserRecordDebounced.cancel();
@@ -125,7 +132,10 @@ function stopRecording() {
125132
}
126133
127134
function onAnySound(amplitude: number) {
135+
audioAmplitude.value = Math.min(Math.max(amplitude, 0), 1);
136+
128137
if(amplitude < 0.01) {
138+
audioAmplitude.value = 0;
129139
showAudioWavesAnimation.value = false;
130140
return;
131141
}

0 commit comments

Comments
 (0)