diff --git a/enjoy/src/api/client.ts b/enjoy/src/api/client.ts index 6038d578..ebf90218 100644 --- a/enjoy/src/api/client.ts +++ b/enjoy/src/api/client.ts @@ -110,6 +110,22 @@ export class Client { return this.api.delete(`/api/posts/${id}`); } + transcriptions(params?: { + page?: number; + items?: number; + targetId?: string; + targetType?: string; + targetMd5?: string; + }): Promise< + { + transcriptions: TranscriptionType[]; + } & PagyResponseType + > { + return this.api.get("/api/transcriptions", { + params: decamelizeKeys(params), + }); + } + syncAudio(audio: Partial) { return this.api.post("/api/mine/audios", decamelizeKeys(audio)); } diff --git a/enjoy/src/renderer/components/posts/post-audio.tsx b/enjoy/src/renderer/components/posts/post-audio.tsx index c1326827..f681c43d 100644 --- a/enjoy/src/renderer/components/posts/post-audio.tsx +++ b/enjoy/src/renderer/components/posts/post-audio.tsx @@ -1,4 +1,5 @@ -import { useEffect, useState, useRef, useCallback } from "react"; +import { useEffect, useState, useRef, useCallback, useContext } from "react"; +import { AppSettingsProviderContext } from "@renderer/context"; import { PitchContour } from "@renderer/components"; import WaveSurfer from "wavesurfer.js"; import { Button, Skeleton } from "@renderer/components/ui"; @@ -19,6 +20,15 @@ export const PostAudio = (props: { threshold: 1, }); const [duration, setDuration] = useState(0); + const { webApi } = useContext(AppSettingsProviderContext); + const [currentTime, setCurrentTime] = useState(0); + const [transcription, setTranscription] = useState(); + + const currentTranscription = (transcription?.result || []).find( + (s) => + currentTime >= s.offsets.from / 1000.0 && + currentTime <= s.offsets.to / 1000.0 + ); const onPlayClick = useCallback(() => { wavesurfer.isPlaying() ? wavesurfer.pause() : wavesurfer.play(); @@ -59,6 +69,9 @@ export const PostAudio = (props: { wavesurfer.on("pause", () => { setIsPlaying(false); }), + wavesurfer.on("timeupdate", (time: number) => { + setCurrentTime(time); + }), wavesurfer.on("decode", () => { setDuration(wavesurfer.getDuration()); const peaks = wavesurfer.getDecodedData().getChannelData(0); @@ -80,6 +93,16 @@ export const PostAudio = (props: { }; }, [wavesurfer]); + useEffect(() => { + webApi + .transcriptions({ + targetMd5: audio.md5, + }) + .then((response) => { + setTranscription(response?.transcriptions?.[0]); + }); + }, [audio.md5]); + return (
@@ -119,6 +142,14 @@ export const PostAudio = (props: { >
+ {currentTranscription && ( +
+
+ {currentTranscription.text} +
+
+ )} + {audio.coverUrl && (
diff --git a/enjoy/src/renderer/components/posts/post-recording.tsx b/enjoy/src/renderer/components/posts/post-recording.tsx index e52e8cc8..0142b8b6 100644 --- a/enjoy/src/renderer/components/posts/post-recording.tsx +++ b/enjoy/src/renderer/components/posts/post-recording.tsx @@ -122,7 +122,7 @@ export const PostRecording = (props: { { recording.referenceText && (
-
+
{recording.referenceText}