URL
https://viettelgroup.ai/voice/api/tts/v1/rest/syn
Method
http POST
Header Parameters
1. header "Content-Type: application/json"
2. header "token: token_id"
Để có "token id" bạn có thể đăng ký tài khoản tại vtcc.ai, sau đó login, rồi vào menu token để tạo
{
"text": "hệ thống tổng hợp tiếng nói trung tâm không gian mạng",
"voice": "doanngocle",
"id": "2",
"without_filter": false,
"speed": 1.0,
"tts_return_option": 2
}
property name | Value | Description |
---|---|---|
text | String | text đầu vào cần tổng hợp. |
voice | String | giọng đọc muốn tổng hợp. |
id | String | ID request do người dụng đặt (có thể dùng để traceback). |
without_filter | Boolean | có sử dụng filter để tăng chất lượng giọng hay không (chậm hơn). |
speed | Float | tốc độ giọng (có giá trị 0.7 - 1.3, tương ứng tốc độ đọc từ x0.7 đến x1.3 lần). |
tts_return_option | Interger | một số dạng integer để chọn api như sau: |
1: streaming | ||
2: wav | ||
3: mp3 |
Mã giọng đọc | Mô tả |
---|---|
doanngocle | Nữ miền Bắc |
phamtienquan | Nam miền Bắc |
lethiyen | Nữ miền Nam |
nguyenthithuyduyen | Nữ miền Nam |
hn-quynhanh | Nữ miền Bắc |
hue-maingoc | Nữ miền Trung |
hue-baoquoc | Nam miền Trung |
hcm-minhquan | Nam miền Nam |
hn-thanhtung | Nam miền Bắc |
hcm-diemmy | Nữ miền Nam |
Bạn có thể lấy danh sách giọng đọc mới nhất thông qua API: https://viettelgroup.ai/voice/api/tts/v1/rest/voices
tạo file data.json như sau:
{
"text": "Hệ thống tổng hợp tiếng nói trung tâm không gian mạng",
"voice": "doanngocle",
"id": "2",
"without_filter": false,
"speed": 1.0,
"tts_return_option": 2
}
command:
curl --header "Content-Type: application/json" --header "token: demo_token" --request POST --data "@data.json" https://vtcc.ai/voice/api/tts/v1/rest/syn > example.wav
#if encounter SSL error because of https certificate, add option '-k' to make insecure connections (this will expose your application to security risks, such as man-in-the-middle attacks.)
output trả về là file: example.wav
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Import the json library
import json
import requests
import urllib
url = "https://viettelgroup.ai/voice/api/tts/v1/rest/syn"
data = {"text": "hôm nay là thứ mấy", "voice": "doanngocle", "id": "2", "without_filter": False, "speed": 1.0, "tts_return_option": 2}
headers = {'Content-type': 'application/json', 'token': 'demo_token'}
response = requests.post(url, data=json.dumps(data), headers=headers)
#if encounter SSL error because of https certificate, please comment out above line and use the line below to make insecure connections (this will expose your application to security risks, such as man-in-the-middle attacks.)
#response = requests.post(url, data=json.dumps(data), headers=headers, verify=False)
# Headers is a dictionary
print(response.headers)
# Get status_code.
print(response.status_code)
# Get the response data as a python object.
data = response.content
f = open("/home/tanpk/log/tanpk.wav", "wb")
f.write(data)
f.close()
public class TestAPI {
public static InputStream getTTS(String apiUrl, String datajson) throws IOException {
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost request = new HttpPost(apiUrl);
StringEntity body = new StringEntity(datajson, "UTF-8");
/*add content-type, token into header request */
request.addHeader("content-type", "application/json;charset=UTF-8");
request.addHeader("token", "demo_token");
request.getRequestLine();
request.setEntity(body);
HttpResponse response = httpClient.execute(request);
System.err.println(response);
return response.getEntity().getContent();
}
public static void main(String[] args) throws IOException {
/*
* create datajon format
* text need to endcode by URLencode
* */
String datajson = "{\"text\":\"xin chào các bạn"," +
"\"voice\":\"doanngocle\"," +
"\"id\":\"3\"," +
"\"without_filter\":false," +
"\"speed\":1.0," +
"\"tts_return_option\":2}";
InputStream result = getTTS("https://viettelgroup.ai/voice/api/tts/v1/rest/syn", datajson);
/* you can write result to file to use */
}
}