python translate方法_GitHub - mufengcoding/python-translate: command line dictionary(命令行词典)...

Python-translate是一个基于Bing、有道和爱词霸翻译服务的简单命令行词典。它支持英语-汉语和汉语-英语翻译、拼写检查、数据存储以及发音功能。用户可以选择不同的翻译服务和发音软件,如espeak和festival。此外,程序还提供了通过-p和-s选项来控制发音和翻译服务的功能。
摘要由CSDN通过智能技术生成

python-translate

python-translate is a simple command line dictionary, it powered by Bing, Youdao and Iciba translation services.

Screenshot

Features

English-Chinese / Chinese-English

Spell checking and suggestion (English only)

Data storage (with dbm module)

Pronunciation

Hyphenation

Usage

usage: translate.py [-h] [-n] [-p {espeak,festival}] [-s {bing,youdao,iciba}]

[-w] [-V]

word

positional arguments:

word word or 'some phrase'

optional arguments:

-h, --help show this help message and exit

-n, --nostorage turn off data storage

-p {espeak,festival,real}, --pronounce {espeak,festival,real}

text-to-speech software: 'espeak', 'festival' or 'real'

-s {bing,youdao,iciba}, --service {bing,youdao,iciba}

translate service: 'bing', 'youdao' or 'iciba'

-w, --webonly ignore local data

-V, --version show program's version number and exit

关于本地数据使用

默认使用本地数据库,如需关闭,可使用 -w 或 --webonly 选项。

~~$ python translate.py hello -w~~

由于原作者用的dbm,我没有找到相应的使用方法,一直报该文件不正确,所以相关代码注释掉或者屏蔽了

关于翻译服务选择

可使用 -s 或 --service 选项指定翻译服务:bing | youdao | iciba ,默认使用必应翻译。以下三种表示方法均有效:

$ python translate.py hello -s=youdao

$ python translate.py hello -s youdao

$ python translate.py hello -syoudao

若该选项非空,则 webonly 会自动开启,即不使用本地数据库。

关于单词发音

单词发音功能默认关闭,如需启用,可使用 -p 或 --pronounce 选项,选择具体的软件发音: espeak | festival 。

另外 TTS 合成语音效果一般,若有真人语音文件,可配合 aplay、mpg321、sox 等命令使用,可修改源码中的 pronounce 部分以更改的发音配置。

$ python translate.py hello -p=espeak

$ python translate.py hello -p=festival

$ python translate.py hello -p=real

Requirements

$ pip install requests beautifulsoup4 lxml pyenchant

# OR

$ pip install -r requirements.txt

eSpeak (for pronunciation, optional)

Festival (for pronunciation, optional)

ALSA (for pronunciation, optional)

$ sudo apt-get install libxml2-dev libxslt-dev python-dev espeak festival alsa-base alsa-utils

Tips

$ alias t="python /path/to/the/translate.py"

$ alias tpe="t -p=espeak"

$ alias tpf="t -p=festival"

$ alias tpr="t -p=real"

$ alias tb="t -s=bing"

$ alias ty="t -s=youdao"

$ alias ti="t -s=iciba"

External Resources

Changelog

v0.1.0

2020-01-09

Initial release

support python3

support statements

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值