From 253d09cebc594f0cc73a0efcf1081e392d5547a2 Mon Sep 17 00:00:00 2001 From: kmein Date: Fri, 27 Jul 2018 11:46:55 +0200 Subject: [PATCH] Hermes: first steps + Add hermes, an assistant for poem translation --- hermes.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 hermes.py diff --git a/hermes.py b/hermes.py new file mode 100644 index 0000000..c9df6a0 --- /dev/null +++ b/hermes.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +import itertools +import subprocess + +from PyDictionary import PyDictionary + +dictionary = PyDictionary() + +def translate_en_de(word): + return dictionary.translate(word, "de") + +def pronunciation(word, lang="de"): + command = ["espeak", "-x", "-q", "-v", lang, word] + return subprocess.check_output(command).decode("utf-8").strip() + +def is_rhyme(word1, word2, lang="de"): + coda1 = itertools.dropwhile(lambda c: c != "'", pronunciation(word1, lang)) + coda2 = itertools.dropwhile(lambda c: c != "'", pronunciation(word2, lang)) + return list(coda1) == list(coda2) + +if __name__ == "__main__": + print(pronunciation("hallo welt")) + print(translate_en_de("woe")) + print(is_rhyme("welt", "geld"))