|
28 | 28 |
|
29 | 29 | let wavesurfer: WaveSurfer | undefined = $state(undefined); |
30 | 30 |
|
| 31 | + let currentTime = $state(0); |
| 32 | +
|
31 | 33 | onMount(() => { |
32 | 34 | if (wavesurfer) { |
33 | 35 | wavesurfer.on('play', () => { |
|
41 | 43 | wavesurfer.on('finish', () => { |
42 | 44 | isPlaying = false; |
43 | 45 | }); |
| 46 | +
|
| 47 | + wavesurfer.on('timeupdate', () => { |
| 48 | + currentTime = wavesurfer?.getCurrentTime() || 0; |
| 49 | + }); |
| 50 | +
|
| 51 | + wavesurfer.on('audioprocess', () => { |
| 52 | + currentTime = wavesurfer?.getCurrentTime() || 0; |
| 53 | + }); |
44 | 54 | } |
45 | 55 | }); |
| 56 | +
|
| 57 | + function playFromTime(start: number) { |
| 58 | + if (wavesurfer) { |
| 59 | + currentTime = start; |
| 60 | + wavesurfer.setTime(currentTime); |
| 61 | + wavesurfer.play(); |
| 62 | + } |
| 63 | + } |
46 | 64 | </script> |
47 | 65 |
|
48 | 66 | <div class="recording-tile" {id}> |
|
58 | 76 |
|
59 | 77 | <RecordingWave {data} bind:wavesurfer /> |
60 | 78 |
|
61 | | - {#if transcription?.text && transcription.text !== `Empty ${id}`} |
| 79 | + {#if transcription?.words?.length} |
62 | 80 | <div class="transcription"> |
63 | 81 | <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> |
| 96 | + {:else} |
| 97 | + <span class="word">{word}</span> |
| 98 | + {/if} |
| 99 | + </span> |
| 100 | + {/each} |
65 | 101 | </div> |
66 | 102 | </div> |
67 | 103 | {:else} |
|
173 | 209 | gap: 1.25rem; |
174 | 210 | place-items: center; |
175 | 211 | } |
| 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 | + } |
176 | 226 | </style> |
0 commit comments