commit 530a6bd3f1056e87bd174329e7f95cf9e491498b Author: cynic Date: Thu May 27 10:04:20 2021 -0400 init! diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc21b8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/cmudict.txt \ No newline at end of file diff --git a/talker.py b/talker.py new file mode 100644 index 0000000..a0ba008 --- /dev/null +++ b/talker.py @@ -0,0 +1,30 @@ +#programs importing this file as a library should load() the phenomes then use talk() to speak +import os +import requests +def talk(word, dict): + print("<", dict[word.upper()]) +def load(): + ps = {} + if not os.path.isfile("cmudict.txt"): + print("downloading phenomes...") + f = open("cmudict.txt", "w", encoding="utf-8") + f.write(requests.get("http://svn.code.sf.net/p/cmusphinx/code/trunk/cmudict/cmudict-0.7b").text) + f.close() + print("loading phenomes...") + f = open("cmudict.txt", "r", encoding="utf-8") + for line in f.read().split("\n"): + if line.startswith(";") or line == "": continue + sp1 = line.split(" ") + ps[sp1[0]] = sp1[1].split(" ") + print("succesfully loaded phenomes") + return ps +def main(): + ps = load() + while True: + inp = input("> ") + try: + for word in inp.split(" "): talk(word, ps) + except: + print("word(s) not in phenome dictionary") +if __name__ == "__main__": + main() \ No newline at end of file