最新消息:

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Python 少儿编程 1891浏览 0评论

上周分享了一个口译机器人的专案,本篇就详细介绍一下如何透过Python 使用 Google Text Translation 文字翻译服务,将文字讯息传送给Google,并透过 Translate 服务来进行文字讯息的转换。注本文中参考使用的硬件平台是Linkit Smart 7688

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

材料准备

1.准备一片 Linkit Smart7688 开发板

2. Linkit Smart 7688 连接至计算机

3.更新 Firmware 0.9.3

https://docs.labs.mediatek.com/resource/linkit-smart-7688/en/downloads

4. USB 声卡透过 OTGCable 安装于 Linkit Smart 7688

5.安装 MIC Speaker 于外接 USB 声卡上

6.安装 USB 声卡相关套件

Linkit Smart 7688 USB 外接声卡连接图

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Google

Step 1. Google 网站申请账号

https://cloud.google.com/

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Step 2. 登入 Google CloudTranslate API 网站

https://cloud.google.com/translate/

Step 3. 点击 VIEW MY CONSOLE

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Step 3. 建立项目

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Step 4. 输入 项目名称

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Step 5. 点击 使用 Google API

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Step 6. 点击 启用 API

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Step 7. 搜寻 Translate

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Step 8. 点击 启用

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Step 9. 点击左边 凭证

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Step 10. 点击 建立凭证

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Step 11. 选择 API 密钥

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Linkit Smart 7688

Step 1. SSH 进入 Linkit Smart 7688

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Step 2. Linkit Smart 7688中建立 GoogleTranslate Python Code

import json

import requests

from requests.packages.urllib3.exceptionsimport InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

googleAPIHost =”https://www.googleapis.com”

key =”AIzaSyC7QHmUMZPSOa_ggF3x86VdwXWEjOq-eAM”

queryString = “hello”

source = “en”

target = “zh-CN”

requestURL = googleAPIHost +”/language/translate/v2?key=” + key + “&source=” +source + “&target=” + target + “&q=” + queryString

print “requestURL: ” + requestURL

response = requests.get(requestURL,verify=False)

print response.status_code

print response.text

decodejson = json.loads(response.text)

print “n” +decodejson["data"]["translations"][0]["translatedText"]

 

Python课程系列:透过 Python使用Google Text Translation文字翻译服务

Step 3. 执行 Python Code

python google_Translate.py

完成,这样在Linkit Smart 7688就可以使用Google Text Translation文字翻译服务啦。

您必须 登录 才能发表评论!