toSpeechLanguage (speech-transformation/language.ts)

airi · packages/core-agent/src/voice/output/speech-transformation/language.ts · typescript · MIT
voice

Functions to extract primary language subtag and detect language from text.

// Source: https://github.com/moeru-ai/airi | License: MIT | Copyright 2024-PRESENT Neko Ayaka
// Provided via justclaw.it.com; keep this notice with the code.
import { primaryLanguage } from '@proj-airi/speech-transformer-math'

/** The primary language subtag of a BCP 47 code, see `primaryLanguage` of `@proj-airi/speech-transformer-math`. */
export function toSpeechLanguage(code: string | undefined): string | undefined {
  return code === undefined ? undefined : primaryLanguage(code) || undefined
}

const kana = /[\p{Script=Hiragana}\p{Script=Katakana}]/u
const hangul = /\p{Script=Hangul}/u
const han = /\p{Script=Han}/u
const latinWord = /[a-z]{2,}/i

/**
 * Selects the language of a formula or a price from the words around it, as a primary language subtag.
 * Han characters without kana

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key