fix ipa convert

This commit is contained in:
an-lee
2024-03-18 14:31:00 +08:00
parent 3541dd9cbf
commit e139899885
3 changed files with 18 additions and 4 deletions

View File

@@ -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;
}
};