V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
musray
V2EX  ›  Python

如何用python脚本启动mac/terminal的朗读功能?

  •  
  •   musray · 2014-01-14 08:09:15 +08:00 · 4940 次点击
    这是一个创建于 3754 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我正在学日语,想用python写一个听写的脚本,但不知道如何可以实现:

    1. OS X 10.9,已经安装日语的语音包
    2. Python 2.7
    3. 功能需求:
    1)任意写一个list,里面包含所有我想听写的单词。
    2)python按10秒一个的速度,让terminal读出list中的单词。(这个到不必非在terminal里发音,我只是暂时想到这里)

    这个如果成功,那日语学习真的就是事半功倍啊!不知道是否可行?
    3 条回复    1970-01-01 08:00:00 +08:00
    Livid
        1
    Livid  
    MOD
       2014-01-14 08:11:05 +08:00   ❤️ 1
    from subprocess import call

    call(['say', 'hello'])
    tan9le
        2
    tan9le  
       2014-01-14 08:42:49 +08:00
    @Livid 哈哈,当时我们有个需求是同一个声源朗读1000多句文本,然后若干设备同时采集来比较解析偏差。实现过程想的超复杂,最后一个哥们幽幽的说:用call就可以了。。。
    musray
        3
    musray  
    OP
       2014-01-14 12:56:38 +08:00
    @Livid 这也太爽了吧!哈哈!

    from subprocess import call
    from time import sleep

    hiragana = {
    '1':'あ',
    '2':'い',
    '3':'う',
    }

    for word in hiragana:
    sleep(2.5)
    call(['say',hiragana[word]])
    sleep(2.5)
    call(['say',hiragana[word]])

    帮看看还能更简单么?!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5767 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 02:32 · PVG 10:32 · LAX 19:32 · JFK 22:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.