Skip to content

Commit e2eb347

Browse files
committed
feat: Highlight words
1 parent df72d45 commit e2eb347

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

apps/web/src/lib/components/RecordingTile/RecordingTile.svelte

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
2929
let wavesurfer: WaveSurfer | undefined = $state(undefined);
3030
31+
let currentTime = $state(0);
32+
3133
onMount(() => {
3234
if (wavesurfer) {
3335
wavesurfer.on('play', () => {
@@ -41,8 +43,24 @@
4143
wavesurfer.on('finish', () => {
4244
isPlaying = false;
4345
});
46+
47+
wavesurfer.on('timeupdate', () => {
48+
currentTime = wavesurfer?.getCurrentTime() || 0;
49+
});
50+
51+
wavesurfer.on('audioprocess', () => {
52+
currentTime = wavesurfer?.getCurrentTime() || 0;
53+
});
4454
}
4555
});
56+
57+
function playFromTime(start: number) {
58+
if (wavesurfer) {
59+
currentTime = start;
60+
wavesurfer.setTime(currentTime);
61+
wavesurfer.play();
62+
}
63+
}
4664
</script>
4765

4866
<div class="recording-tile" {id}>
@@ -58,10 +76,28 @@
5876

5977
<RecordingWave {data} bind:wavesurfer />
6078

61-
{#if transcription?.text && transcription.text !== `Empty ${id}`}
79+
{#if transcription?.words?.length}
6280
<div class="transcription">
6381
<div class="inner">
64-
{transcription.text}
82+
<!-- svelte-ignore a11y_click_events_have_key_events -->
83+
{#each transcription.words as { word, start, end }, i}
84+
<!-- svelte-ignore a11y_click_events_have_key_events -->
85+
<!-- svelte-ignore a11y_no_static_element_interactions -->
86+
<span
87+
class="word-wrapper"
88+
data-start={start}
89+
data-end={end}
90+
class:highlight={currentTime >= start && currentTime <= end}
91+
class:read={currentTime >= start}
92+
onclick={() => playFromTime(start)}
93+
>
94+
{#if i !== transcription.words.length - 1}
95+
<span class="word">{word}</span>&nbsp;
96+
{:else}
97+
<span class="word">{word}</span>
98+
{/if}
99+
</span>
100+
{/each}
65101
</div>
66102
</div>
67103
{:else}
@@ -173,4 +209,18 @@
173209
gap: 1.25rem;
174210
place-items: center;
175211
}
212+
213+
.word {
214+
color: var(--c-text-light);
215+
cursor: pointer;
216+
217+
.read & {
218+
color: var(--c-text);
219+
}
220+
221+
.highlight & {
222+
color: black;
223+
background-color: yellow;
224+
}
225+
}
176226
</style>

apps/web/src/routes/+layout.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<script>
2-
import { afterNavigate, goto, invalidate } from '$app/navigation';
2+
import { afterNavigate, invalidate } from '$app/navigation';
33
import Header from '$lib/components/Header.svelte';
44
import { page } from '$app/stores';
55
import '$lib/styles/index.css';
66
import Button from '$lib/components/Button.svelte';
77
import Logo from '$lib/components/Logo.svelte';
8-
import ButtonRecord from '$lib/components/ButtonRecord.svelte';
98
109
export let data;
1110

0 commit comments

Comments
 (0)