diff --git a/README.md b/README.md index e81dbe7..74ae634 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,10 @@ pip install ici ### 使用方法: -$ ici what - +$ ici [-p] what +argument: + -p  查词的同时播放读音(需要mpg123); + [wɒt] [wɑ:t] diff --git a/ici/ici.py b/ici/ici.py index 8bd03f6..ea265da 100644 --- a/ici/ici.py +++ b/ici/ici.py @@ -6,6 +6,7 @@ import sys import getopt import logging +import subprocess from xml.dom import minidom from collections import namedtuple try: @@ -59,9 +60,15 @@ def show(node): show(e) +def pronounce(node): + elements = node.getElementsByTagName("pron") + pron_urls = [a.firstChild.data for a in elements] + subprocess.Popen("mpg123 -q " + " ".join(pron_urls), shell=True) + + def main(): try: - options, args = getopt.getopt(sys.argv[1:], ["help"]) + options, args = getopt.getopt(sys.argv[1:], "p", ["help"]) except getopt.GetoptError as e: pass @@ -72,6 +79,9 @@ def main(): return root = read_xml(response) show(root) + for option in options: + if '-p' in option: + pronounce(root) if __name__ == '__main__':