UNPKG

arpabet-and-ipa-convertor-ts

Version:

Typescript code to convert between Arpabet and IPA phonetic transcriptions

56 lines (55 loc) 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Word = void 0; var stress_1 = require("./stress"); var Word = /** @class */ (function () { function Word() { this.syllables = []; this.stressCount = 0; } Word.prototype.addSyllable = function (syllable) { if (((!syllable) || syllable.isEmpty())) { return; } this.syllables.push(syllable); if (syllable.haveVowel) { this.stressCount += 1; } }; Word.prototype.toArpabet = function () { var _this = this; var translations = this.syllables.map(function (syllable) { if ((syllable.haveVowel && (_this.stressCount <= 1))) { syllable.stress = stress_1.Stress.Primary; } return syllable.toArpabet(); }); return translations.join(' '); }; Word.prototype.toAmericanPhoneticAlphabet = function () { var _this = this; var translations = ''; this.syllables.forEach(function (syllable, i) { translations += syllable.toAmericanPhoneticAlphabet(((0 === i) && (1 >= _this.stressCount))); }); return translations; }; Word.prototype.toEnglishPhoneticAlphabet = function () { var _this = this; var translations = ''; this.syllables.forEach(function (syllable, i) { translations += syllable.toEnglishPhoneticAlphabet(((0 === i) && (1 >= _this.stressCount))); }); return translations; }; Word.prototype.toIPA = function () { var _this = this; var translations = ''; this.syllables.forEach(function (syllable, i) { translations += syllable.toIPA((0 === i) && (1 >= _this.stressCount)); }); return translations; }; return Word; }()); exports.Word = Word;