def getipa(): getipa = {} if request.method == "POST": text = request.json.get("text") else: text = request.args.get("text") mlphon = PhoneticAnalyser() ipa = mlphon.grapheme_to_phoneme(text) return jsonify({"text": text, "IPA": ipa})
def g2p_analyse(): grapheme_analyse = {} if request.method == "POST": text = request.json.get("text") else: text = request.args.get("text") text = text.strip() mlphon = PhoneticAnalyser() ipa_and_tags = mlphon.analyse(text) # ipa_and_tags = [{'phonemes': [{'ipa': 'k', 'tags': ['plosive', 'voiceless', 'unaspirated', 'velar']}, {'ipa': 'a', 'tags': ['schwa']}]}, {'phonemes': [{'ipa': 'l', 'tags': ['lateral', 'alveolar']}, {'ipa': 'a', 'tags': ['schwa']}]}] return jsonify({"text": text, "syllables": ipa_and_tags})
def syllablize(): """Syllablize the input Malayalam string obtained by POST Example: കേരളം Returns ------- json syllables:["കേ","ര", "ളം"] 0: "കേ" 1: "ര" 2: "ളം" text:"കേരളം" """ syllablize = {} if request.method == "POST": text = request.json.get("text") else: text = request.args.get("text") text = text.strip() mlphon = PhoneticAnalyser() syllables = mlphon.split_to_syllables(text) return jsonify({"text": text, "syllables": syllables})
class AnalyserGeneratorTests(unittest.TestCase): def setUp(self): self.csvfile = open(os.path.join(CURR_DIR, "data_syllable.tsv")) self.datasyl = csv.reader(self.csvfile, delimiter="\t") self.mlphon = PhoneticAnalyser() def tearDown(self): self.csvfile.close() def test_analyse(self): for row in self.datasyl: with self.subTest(): anals = self.mlphon.split_to_syllables(row[0]) match = False self.assertTrue(len(anals) != 0, "Syllablize failed for " + row[0]) print(row[0], "\t-->\t", anals) if row[1] == str(anals): match = True self.assertEqual(match, True, "Syllablize for " + row[1])
class G2PTests(unittest.TestCase): def setUp(self): self.csvfile = open(os.path.join(CURR_DIR, "data_g2p.tsv")) self.data_g2p = csv.reader(self.csvfile, delimiter="\t") self.mlphon = PhoneticAnalyser() def tearDown(self): self.csvfile.close() def test_g2p(self): for row in self.data_g2p: with self.subTest(): result_g2p = self.mlphon.grapheme_to_phoneme(row[0]) match = False self.assertTrue( len(result_g2p) != 0, "Analysis failed for " + row[0]) print(row[0], "\t-->\t", result_g2p) for index in range(len(result_g2p)): if row[1] == str(result_g2p): match = True break self.assertEqual(match, True, "Analysis for " + row[0])
def g2p_generate(): grapheme_generate = {} text = request.args.get("text") mlphon = PhoneticAnalyser() graphemes = mlphon.phoneme_to_grapheme(text) return jsonify({"text": text, "IPA": graphemes})
def setUp(self): self.csvfile = open(os.path.join(CURR_DIR, "data_syllable.tsv")) self.datasyl = csv.reader(self.csvfile, delimiter="\t") self.mlphon = PhoneticAnalyser()