UNPKG

arpabet-and-ipa-convertor-ts

Version:

Typescript code to convert between Arpabet and IPA phonetic transcriptions

79 lines (78 loc) 3.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Syllable = void 0; var stress_1 = require("./stress"); var Syllable = /** @class */ (function () { function Syllable() { this.stress = null; this._haveVowel = false; this.phonemes = []; } Object.defineProperty(Syllable.prototype, "haveVowel", { get: function () { return this._haveVowel; }, enumerable: false, configurable: true }); Syllable.prototype.isEmpty = function () { return (this.phonemes.length <= 0); }; Syllable.prototype.addPhoneme = function (phoneme) { if ((!phoneme)) { return; } this.phonemes.push(phoneme); if (phoneme.isVowel) { if ((!this.stress)) { this.stress = stress_1.Stress.No; } this._haveVowel = true; } }; Syllable.prototype.toArpabet = function () { var _this = this; // 转换成arpabet return this.phonemes.map(function (phoneme) { var _a; if (phoneme.isVowel) { return phoneme.arpabet + ((_a = _this.stress) === null || _a === void 0 ? void 0 : _a.markArpabet()); } else { return phoneme.arpabet; } }).join(' '); }; Syllable.prototype.toAmericanPhoneticAlphabet = function (hideStressMark) { var _a; if (hideStressMark === void 0) { hideStressMark = false; } // 转换成美音音。只要一个元音的时候需要隐藏重音标识 var translations = (((!hideStressMark) && this.haveVowel) ? (_a = this.stress) === null || _a === void 0 ? void 0 : _a.markIpa() : ""); this.phonemes.forEach(function (phoneme) { translations += phoneme.american; }); return translations; }; Syllable.prototype.toEnglishPhoneticAlphabet = function (hideStressMark) { var _a; if (hideStressMark === void 0) { hideStressMark = false; } // 转换成英音。只要一个元音的时候需要隐藏重音标识 var translations = (((!hideStressMark) && this.haveVowel) ? (_a = this.stress) === null || _a === void 0 ? void 0 : _a.markIpa() : ""); this.phonemes.forEach(function (phoneme) { translations += phoneme.english; }); return translations; }; Syllable.prototype.toIPA = function (hideStressMark) { var _a; if (hideStressMark === void 0) { hideStressMark = false; } // 转换成国际音标。只要一个元音的时候需要隐藏重音标识ß var translations = (((!hideStressMark) && this.haveVowel) ? (_a = this.stress) === null || _a === void 0 ? void 0 : _a.markIpa() : ""); this.phonemes.forEach(function (phoneme) { translations += phoneme.ipa; }); return translations; }; return Syllable; }()); exports.Syllable = Syllable;