Skip to Content

glost-transcription

Transcription/romanization plugin for GLOST documents.

Installation

pnpm add @glotblocks/glost-transcription

Usage

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:

  1. Visits each word node in the document
  2. Calls the lookupTranscription function with the word text
  3. Merges returned transcription data into word.transcription

Example API Response

{ "rtgs": "sawatdi", "ipa": "sa.wàt.diː", "paiboon": "sa-wat-dii" }

Supported Transcription Systems

SystemLanguageDescription
ipaUniversalInternational Phonetic Alphabet
rtgsThaiRoyal Thai General System
auaThaiAUA Romanization
paiboonThaiPaiboon+ System
romajiJapaneseRoman letters
furiganaJapaneseHiragana reading aid
pinyinChineseStandard 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