diff --git a/README.md b/README.md index 3907ef6..200b12b 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,7 @@ NEXT_PUBLIC_URL_MEILISEARCH=https://url-to.search-accords-library.com NEXT_PUBLIC_MEILISEARCH_KEY=abcdef0123456789 NEXT_PUBLIC_UMAMI_URL=https://url-to.umami-accords-library.com NEXT_PUBLIC_UMAMI_ID=abcdef0123456789 +NEXT_PUBLIC_API_OCR_KEY=abcdef0123456789 ``` Run in dev mode: diff --git a/src/pages/dev/transcript.tsx b/src/pages/dev/transcript.tsx index 7f7bd8e..b4b7e84 100644 --- a/src/pages/dev/transcript.tsx +++ b/src/pages/dev/transcript.tsx @@ -1,7 +1,8 @@ import "@fontsource/noto-serif-jp"; import { GetStaticProps } from "next"; -import { useCallback, useRef, useState } from "react"; +import { ChangeEvent, useCallback, useRef, useState } from "react"; import { atomWithStorage } from "jotai/utils"; +import { TransformComponent, TransformWrapper } from "react-zoom-pan-pinch"; import { AppLayout, AppLayoutRequired } from "components/AppLayout"; import { Button } from "components/Inputs/Button"; import { ButtonGroup } from "components/Inputs/ButtonGroup"; @@ -10,6 +11,7 @@ import { ToolTip } from "components/ToolTip"; import { getOpenGraph } from "helpers/openGraph"; import { getFormat } from "helpers/i18n"; import { atomPairing, useAtomPair } from "helpers/atoms"; +import { cIf, cJoin } from "helpers/className"; /* * ╭─────────────╮ @@ -366,27 +368,81 @@ const Transcript = (props: Props): JSX.Element => { [updateDisplayedText] ); + const [image, setImage] = useState(); + + const onImageUploaded = useCallback( + async (event: ChangeEvent) => { + const file = event.target.files?.[0]; + if (file) { + const formData = new FormData(); + formData.append("file", file); + formData.append("language", "jpn"); + formData.append("FileType", ".Auto"); + formData.append("scale", "true"); + formData.append("OCREngine", "1"); + + type OCRApiResponse = { + ParsedResults: { + ParsedText: string; + }[]; + OCRExitCode: number; + IsErroredOnProcessing: boolean; + }; + + const response = await fetch("https://api.ocr.space/parse/image", { + method: "POST", + body: formData, + headers: { apiKey: "d35acb001e88957" }, + }); + + const jsonData: OCRApiResponse = await response.json(); + const ocrText = jsonData.ParsedResults[0]?.ParsedText; + + if (ocrText) { + setText(ocrText); + } + + setImage(URL.createObjectURL(file)); + } + }, + [setText] + ); + const contentPanel = ( - -
+ +