From e1398998856bcd14242fdfefcc3400e444366e5f Mon Sep 17 00:00:00 2001 From: an-lee Date: Mon, 18 Mar 2024 14:31:00 +0800 Subject: [PATCH] fix ipa convert --- enjoy/src/constants.ts | 2 +- .../renderer/components/medias/media-caption.tsx | 7 ++++--- enjoy/src/utils.ts | 13 +++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/enjoy/src/constants.ts b/enjoy/src/constants.ts index a66b26b3..d8dbd556 100644 --- a/enjoy/src/constants.ts +++ b/enjoy/src/constants.ts @@ -390,7 +390,7 @@ export const IPA_MAPPING: { [key: string]: string } = { r: "r", ʀ: "r", ⱱ: "", - ɾ: "r", + ɾ: "t", ɽ: "r", ɸ: "f", β: "v", diff --git a/enjoy/src/renderer/components/medias/media-caption.tsx b/enjoy/src/renderer/components/medias/media-caption.tsx index 35f4511e..17519ada 100644 --- a/enjoy/src/renderer/components/medias/media-caption.tsx +++ b/enjoy/src/renderer/components/medias/media-caption.tsx @@ -8,6 +8,7 @@ import { Timeline } from "echogarden/dist/utilities/Timeline.d.js"; import { IPA_MAPPING } from "@/constants"; import { useAiCommand } from "@renderer/hooks"; import { LoaderIcon } from "lucide-react"; +import { convertIpaToNormal } from "@/utils"; export const MediaCaption = () => { const { @@ -353,7 +354,7 @@ export const MediaCaption = () => { {caption.timeline[index].timeline .map((t) => t.timeline - .map((s) => IPA_MAPPING[s.text] || s.text) + .map((s) => convertIpaToNormal(s.text)) .join("") ) .join(" · ")} @@ -382,7 +383,7 @@ export const MediaCaption = () => { {w.timeline .map((t) => t.timeline - .map((s) => IPA_MAPPING[s.text] || s.text) + .map((s) => convertIpaToNormal(s.text)) .join("") ) .join(" · ")} @@ -421,7 +422,7 @@ export const MediaCaption = () => { {word.timeline .map((t) => t.timeline - .map((s) => IPA_MAPPING[s.text] || s.text) + .map((s) => convertIpaToNormal(s.text)) .join("") ) .join(" · ")} diff --git a/enjoy/src/utils.ts b/enjoy/src/utils.ts index 6bac835b..6eefd220 100644 --- a/enjoy/src/utils.ts +++ b/enjoy/src/utils.ts @@ -1,5 +1,6 @@ import Pitchfinder from "pitchfinder"; import { END_OF_SENTENCE_REGEX, MAGIC_TOKEN_REGEX } from "./constants"; +import { IPA_MAPPING } from "./constants"; export const extractFrequencies = (props: { peaks: Float32Array; @@ -86,3 +87,15 @@ export const groupTranscription = ( return groups; }; + +export const convertIpaToNormal = (ipa: string) => { + const mark = ipa.match(/(\ˈ|ˌ)/); + const cleanIpa = ipa.replace(mark ? mark[0] : "", ""); + + const converted = IPA_MAPPING[cleanIpa] || cleanIpa; + if (mark) { + return `${mark[0]}${converted}`; + } else { + return converted; + } +};