FREE TRANSLATION API
免费翻译 API
无需 API Key,通过一个简单的 GET 请求完成自动语言识别和翻译。适合个人项目、脚本和快速原型。
GET https://www.kozyax.site/trans?q=hello&tl=zh-CNTRY IT ONLINE
在线调用
在这里直接调用翻译 API,结果与程序调用完全一致。
翻译结果
快速开始
请求参数
| q | 要翻译的文本,必填,最多 5,000 个字符。 |
|---|---|
| tl | 目标语言代码,可选,默认 zh-CN。 |
返回示例
{
"text": "你好",
"source": "en",
"target": "zh-CN",
"original": "hello"
}全部支持语言与 tl 参数
接口使用 Google Translate 的语言代码。请求时将下表的 tl 值作为目标语言参数,例如 /trans?q=hello&tl=ja。完整 JSON 列表:GET /api/languages。
| 语言 | tl 参数值 | 调用示例 |
|---|---|---|
| 语言列表加载中... | ||
语音列表
翻译接口返回文字,不直接生成音频。可用语音语言列表:GET /api/voices。浏览器端可使用 SpeechSynthesis 朗读翻译结果。
JavaScript
const result = await fetch('/trans?q=hello&tl=zh-CN').then(r => r.json());
const utterance = new SpeechSynthesisUtterance(result.text);
utterance.lang = result.target;
speechSynthesis.speak(utterance);
调用示例
PHP
$result = file_get_contents(
'https://www.kozyax.site/trans?q=' . urlencode('Hello') . '&tl=zh-CN'
);
$data = json_decode($result, true);
echo $data['text'];Python
import requests
r = requests.get(
'https://www.kozyax.site/trans',
params={'q': 'Hello', 'tl': 'zh-CN'}
)
print(r.json()['text'])JavaScript
const response = await fetch(
'/trans?q=' + encodeURIComponent('Hello') + '&tl=zh-CN'
);
console.log((await response.json()).text);cURL
curl 'https://www.kozyax.site/trans?q=Hello&tl=zh-CN'Go
package main
import (
"fmt"
"io"
"net/http"
)
func main() {
resp, err := http.Get("https://www.kozyax.site/trans?q=Hello&tl=zh-CN")
if err != nil { panic(err) }
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
var request = HttpRequest.newBuilder()
.uri(URI.create("https://www.kozyax.site/trans?q=Hello&tl=zh-CN"))
.GET().build();
var response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}使用限制
单次文本最多 5,000 个字符,每分钟最多 30 次。服务不需要 API Key,但请合理使用,避免高频或批量请求。