glost-transcription
Transcription/romanization plugin for GLOST documents.
Installation
pnpm add @glotblocks/glost-transcriptionUsage
createTranscriptionPlugin
Create a plugin that adds transcription data to words.
import { createTranscriptionPlugin } from '@glotblocks/glost-transcription';
const transcriptionPlugin = createTranscriptionPlugin({
targetLanguage: "th",
lookupTranscription: async (word, language) => {
// Return transcription data for the word
return {
rtgs: "sawatdi",
ipa: "sa.wàt.diː",
paiboon: "sa-wat-dii"
};
}
});Options
interface TranscriptionPluginOptions {
targetLanguage: GlostLanguage;
lookupTranscription?: (
word: string,
language: GlostLanguage
) => Promise<Record<string, string> | undefined>;
}Processing
Use with the v0.5+ processor API:
import { glost } from '@glotblocks/glost';
import { createTranscriptionPlugin } from '@glotblocks/glost-transcription';
const transcriptionPlugin = createTranscriptionPlugin({
targetLanguage: "th",
lookupTranscription: async (word, lang) => {
const response = await fetch(
`/api/transcription/${lang}/${encodeURIComponent(word)}`
);
if (!response.ok) return undefined;
return response.json();
}
});
const result = await glost()
.use(transcriptionPlugin)
.process(document);What It Does
The plugin:
- Visits each word node in the document
- Calls the
lookupTranscriptionfunction with the word text - Merges returned transcription data into
word.transcription
Example API Response
{
"rtgs": "sawatdi",
"ipa": "sa.wàt.diː",
"paiboon": "sa-wat-dii"
}Supported Transcription Systems
| System | Language | Description |
|---|---|---|
ipa | Universal | International Phonetic Alphabet |
rtgs | Thai | Royal Thai General System |
aua | Thai | AUA Romanization |
paiboon | Thai | Paiboon+ System |
romaji | Japanese | Roman letters |
furigana | Japanese | Hiragana reading aid |
pinyin | Chinese | Standard romanization |
Combining with Other Extensions
import { processGLOSTWithExtensionsAsync } from '@glotblocks/glost-plugins';
import { createTranscriptionGeneratorExtension } from '@glotblocks/glost-transcription';
import { createTranslationGeneratorExtension } from '@glotblocks/glost-translation';
import { createFrequencyExtension } from '@glotblocks/glost-frequency';
import { createDifficultyExtension } from '@glotblocks/glost-difficulty';
// Create extensions
const transcription = createTranscriptionGeneratorExtension({
targetLanguage: 'th',
provider: myTranscriptionProvider
});
const translation = createTranslationGeneratorExtension({
targetLanguage: 'th',
nativeLanguage: 'en',
provider: myTranslationProvider
});
const [freqGen, freqEnh] = createFrequencyExtension({
targetLanguage: 'th',
provider: myFrequencyProvider
});
const result = await processGLOSTWithExtensionsAsync(document, [
transcription,
translation,
freqGen, freqEnh
]);Last updated on