要使用谷歌翻译API,首先需要安装Google Cloud SDK。可以按照以下步骤进行安装: 访问Google Cloud SDK官方文档:https://cloud.google.com/sdk/docs/install 根据操作系统选择相应的安装方式 安装完成后,运行gcloud init命令,按照提示进行身份验证和项目设置 启用Google Translate API ...
https://console.cloud.google.com 1.创建项目 2.您需要为此项目提供一个计费帐户,然后才能激活该服务。 访问API控制台以配置结算帐户,然后返回此处继续操作。 3.下载秘钥 4.为项目开启API功能 5.搜索需要开启的API类型 6.创建API Key 服务器中先安装composer composer require google/cloud-translate 记得...
---## 一、准备工作### 1.1 创建Google Cloud项目1.访问[Google Cloud Console](https://console.cloud.google.com/)2.点击"创建项目"并填写项目名称3.记下生成的**项目ID**(后续需要用到)### 1.2 启用Translation API1.在导航菜单选择"API和服务">"库"2.搜索"Cloud Translation API"3.点击"启用"按钮...
$newfname = '1.wmv'; $reqBaseURL = 'http://translate.google.com/translate_tts?tl=en&q=how%20do%20you%20do'; $remote_file = fopen($reqBaseURL, "rb"); if ($remote_file){ $newf = fopen($newfname, "wb"); if ($newf){ while(!feof($remote_file)){ fwrite($newf, fread($...
<?php $text = "Hello this is a test for voice api of google"; // Name of the MP3 file generated using the MD5 hash $file = md5($text); // Save the MP3 file in this folder with the .mp3 extension $file = "audio/" . $file .".mp3"; if($file) { echo "created"; } else...
class Google_API_translator { public $url = “http://translate.google.com/translate_t”; public $text = “”;//翻译文本 public $out = “”; //翻译输出 function setText($text){ $this->text = $text; } function translate() {
$g = new Google_API_translator(); $g->setOpts(array("text" => "Cjjer是天才", "language_pair" => "zh-CN|en")); $g->translate(); echo $g->out; ?> 这样就可以了,输出:Cjjer is genius PHP的就这里,参见了部分同学的部分代码。具体忘了。
很多人可能看到GoogleTranslate是基于Google在线翻译的,可能会怀疑它的稳定性,虽然Google搜索在国内是被墙了,但是Google翻译是通过translate.Google.cn来访问的,因此不用FQ就可以直接使用。唯一的问题就是GoogleTranslate这款火车头数据采集软件插件是通过抓取Google在线翻译来实现的,不保证以后Google会改变网页规则。
方法一:使用Google Translate插件 1. 首先,在谷歌翻译平台创建一个新的项目,获得翻译API密钥。 2. 在PHP代码中,使用curl库进行HTTP请求,将要翻译的文本以及API密钥作为参数发送给Google Translate API。 3. 解析Google Translate API的响应,获取翻译后的文本。
今天用google翻译时,发现个好东西:Google translate_tts,调用这个api就可以听到英文发音, 省掉了自己上传音频文件的麻烦。 我用php写了个调用的方法,可以把音频文件保存在本地。 如下: 复制代码代码如下: $newfname = '1.wmv'; $reqBaseURL = 'http://translate.google.com/translate_tts?tl=en&q=how%20do...