tts (Premium)
- Print
- PDF
tts (Premium)
- Print
- PDF
Article Summary
Share feedback
Thanks for sharing your feedback!
Overview
CLOVA Voice - Premium API is an HTTP-based REST API that synthesizes speech from text using parameters, such as tone, speed, and emotion.
Requests
curl -i -X POST \
-H "Content-Type:application/x-www-form-urlencoded" \
-H "X-NCP-APIGW-API-KEY-ID:{Client ID value issued upon registering the application}" \
-H "X-NCP-APIGW-API-KEY:{Client secret value issued upon registering the application}" \
-d 'speaker={voice type}&text={text}&volume={volume}&speed={speech playback speed}&pitch={pitch}’ \
'https://naveropenapi.apigw.ntruss.com/tts-premium/v1/tts'
Request parameters
Parameter name | Type | Description | Default value | Requirement status |
---|---|---|---|---|
speaker | string | Type of voice to use for speech synthesis
| None | Y |
text | string | - Sentence to be synthesized - Supports UTF-8-encoded text only - Speech synthesis of up to 2000 characters - Does not read symbols or text in parentheses | None | Y |
volume | integer | - Speech volume - Integer value between (-)5 and 5 - (-)5 for 0.5 times lower volume, 5 for 1.5 times higher volume, and 0 for normal volume for speech synthesis | 0 | N |
speed | integer | - Speech speed - Integer value between (-)5 and 5 - (-)5 for 2 times faster speed, 5 for 0.5 times slower speed, and 0 for normal speed for speech synthesis | 0 | N |
pitch | integer | - Speech pitch - Integer value between (-)5 and 5 - (-)5 for 1.2 times higher pitch, 5 for 0.8 times lower pitch, and 0 for normal pitch for speech synthesis | 0 | N |
emotion | integer | - Speech emotion - Integer value between 0 and 3 - Supported speakers: nara, vara, vmikyung, vdain, vyuna (however, 3: angry is not supported by nara) | 0 | N |
emotion-strength | integer | - Intensity of emotion - Supported speakers: vara, vmikyung, vdain, vyuna (nara not supported) | 1 | N |
format | string | - Speech format - mp3 or wav | mp3 | N |
sampling-rate | integer | - Sampling rate - Supported only in WAV format; MP3 format is fixed at 24000 and cannot be changed However, mijin only supports 16000 | 24000 | N |
alpha | integer | - Tone - Integer value between (-)5 and 5 - Higher tone when greater than 0, lower tone when less than 0 | 0 | N |
end-pitch | integer | - End-pitch processing - Integer value between (-)5 and 5 Raise the end of the sentence if greater than 0, and lower the end of the sentence if less than 0 - Supported speakers: speakers starting with "d" (e.g., dara, danna) and clara, matt, meimei, liangliang, chiahua, kuanlin, carmen, jose | 0 | N |
Request headers
Header name | Description |
---|---|
X-NCP-APIGW-API-KEY-ID | Client ID issued upon registering the appX-NCP-APIGW-API-KEY-ID:{Client ID} |
X-NCP-APIGW-API-KEY | Client secret issued upon registering the appX-NCP-APIGW-API-KEY:{Client Secret} |
Content-Type | Fixed as application/x-www-form-urlencodedContent-Type: application/x-www-form-urlencoded |
Request bodies
- This API does not require request bodies.
Responses
Response bodies
- Binary MP3 or WAV data
Examples
Request examples
curl -i -X POST \
-H "Content-Type:application/x-www-form-urlencoded" \
-H "X-NCP-APIGW-API-KEY-ID:{Client ID value issued upon registering the application}" \
-H "X-NCP-APIGW-API-KEY:{Client secret value issued upon registering the application}" \
-d 'speaker=nara&text=Nice to meet you&volume=0&speed=0&pitch=0&format=mp3' \
'https://naveropenapi.apigw.ntruss.com/tts-premium/v1/tts'
Response examples
[HTTP Response Header]
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 09 Sep 2020 02:35:50 GMT
Content-Type: audio/mpeg
Content-Length: 15216
Connection: keep-alive
Keep-Alive: timeout=5
Playtime: 1890
X-Chars-Count: 6
X-QUOTA: 1
X-Ssgw-Request-Id: f53c46c5-cce6-4943-b986-47ba752f8937
X-Text-Length: 26
[HTTP Response Body]
{Binary data in MP3 format}
API examples
// NAVER speech synthesis open API example
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Date;
public class APIExamTTS {
public static void main(String[] args) {
String clientId = "YOUR_CLIENT_ID";//Application client ID value";
String clientSecret = "YOUR_CLIENT_SECRET";//Application client secret value";
try {
String text = URLEncoder.encode("Nice to meet you.", "UTF-8"); // 13 characters
String apiURL = "https://naveropenapi.apigw.ntruss.com/tts-premium/v1/tts";
URL url = new URL(apiURL);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("X-NCP-APIGW-API-KEY-ID", clientId);
con.setRequestProperty("X-NCP-APIGW-API-KEY", clientSecret);
// post request
String postParams = "speaker=nara&volume=0&speed=0&pitch=0&format=mp3&text=" + text;
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(postParams);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
BufferedReader br;
if(responseCode==200) { // Successful call
InputStream is = con.getInputStream();
int read = 0;
byte[] bytes = new byte[1024];
// Randomly generates the MP3 file name
String tempname = Long.valueOf(new Date().getTime()).toString();
File f = new File(tempname + ".mp3");
f.createNewFile();
OutputStream outputStream = new FileOutputStream(f);
while ((read =is.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
is.close();
} else { // Error occurred
br = new BufferedReader(new InputStreamReader(con.getErrorStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = br.readLine()) != null) {
response.append(inputLine);
}
br.close();
System.out.println(response.toString());
}
} catch (Exception e) {
System.out.println(e);
}
}
}
// NAVER speech synthesis open API example
<?php
$client_id = "YOUR_CLIENT_ID";
$client_secret = "YOUR_CLIENT_SECRET";
$encText = urlencode("Nice to meet you.");
$postvars = "speaker=nara&volume=0&speed=0&pitch=0&format=mp3&text=".$encText;
$url = "https://naveropenapi.apigw.ntruss.com/tts-premium/v1/tts";
$is_post = true;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, $is_post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $postvars);
$headers = array();
$headers[] = "X-NCP-APIGW-API-KEY-ID: ".$client_id;
$headers[] = "X-NCP-APIGW-API-KEY: ".$client_secret;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo "status_code:".$status_code."<br/>";
curl_close ($ch);
if($status_code == 200) {
//echo $response;
$fp = fopen("tts.mp3", "w+");
fwrite($fp, $response);
fclose($fp);
echo "<a href='tts.mp3'>play TTS</a>";
} else {
echo "Error content:".$response;
}
?>
// NAVER speech synthesis open API example
var express = require('express');
var app = express();
var client_id = 'YOUR_CLIENT_ID';
var client_secret = 'YOUR_CLIENT_SECRET';
var fs = require('fs');
app.get('/tts', function(req, res) {
var api_url = 'https://naveropenapi.apigw.ntruss.com/tts-premium/v1/tts';
var request = require('request');
var options = {
url: api_url,
form: { speaker: 'nara', volume: '0', speed: '0', pitch: '0', text: 'Have a good day', format: 'mp3' },
headers: { 'X-NCP-APIGW-API-KEY-ID': client_id, 'X-NCP-APIGW-API-KEY': client_secret },
};
var writeStream = fs.createWriteStream('./tts1.mp3');
var _req = request.post(options).on('response', function(response) {
console.log(response.statusCode); // 200
console.log(response.headers['content-type']);
});
_req.pipe(writeStream); // Output to file
_req.pipe(res); // Output to browser
});
app.listen(3000, function() {
console.log('http://127.0.0.1:3000/tts app listening on port 3000!');
});
// NAVER speech synthesis open API example
import os
import sys
import urllib.request
client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
encText = urllib.parse.quote("Hello, NAVER")
data = "speaker=nara&volume=0&speed=0&pitch=0&format=mp3&text=" + encText;
url = "https://naveropenapi.apigw.ntruss.com/tts-premium/v1/tts"
request = urllib.request.Request(url)
request.add_header("X-NCP-APIGW-API-KEY-ID",client_id)
request.add_header("X-NCP-APIGW-API-KEY",client_secret)
response = urllib.request.urlopen(request, data=data.encode('utf-8'))
rescode = response.getcode()
if(rescode==200):
print("save TTS mp3")
response_body = response.read()
with open('1111.mp3', 'wb') as f:
f.write(response_body)
else:
print("Error Code:" + rescode)
# -*- coding: utf-8 -*-
import os
import sys
import urllib
import urllib2
reload(sys)
sys.setdefaultencoding('utf-8')
client_id = "YOUR_CLIENT_ID" # application client ID value";
client_secret = "YOUR_CLIENT_SECRET" # application client secret value"
text = unicode("Hello, NAVER") # sentence for speech synthesis
speaker = "nara" # type of voice to use for speech synthesis
speed = "0" # speech playback speed
volume = "0" # speech volume
pitch = "0" # speech pitch
fmt = "mp3" # speech format
val = {
"speaker": speaker,
"volume": volume,
"speed":speed,
"pitch": pitch,
"text":text,
"format": fmt
}
data = urllib.urlencode(val)
url = "https://naveropenapi.apigw.ntruss.com/tts-premium/v1/tts"
headers = {
"X-NCP-APIGW-API-KEY-ID" : client_id,
"X-NCP-APIGW-API-KEY" : client_secret
}
request = urllib2.Request(url, data, headers)
response = urllib2.urlopen(request)
rescode = response.getcode()
if(rescode==200):
print("TTS mp3 save")
response_body = response.read()
with open('1111.mp3', 'wb') as f:
f.write(response_body)
else:
print("Error Code:" + rescode)
// NAVER speech synthesis open API example
using System;
using System.Net;
using System.Text;
using System.IO;
namespace NaverAPI_Guide
{
public class APIExamTTS
{
static void Main(string[] args)
{
string text = "Have a good day."; // Character value for speech synthesis
string url = "https://naveropenapi.apigw.ntruss.com/tts-premium/v1/tts";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("X-NCP-APIGW-API-KEY-ID", "YOUR-CLIENT-ID");
request.Headers.Add("X-NCP-APIGW-API-KEY", "YOUR-CLIENT-SECRET");
request.Method = "POST";
byte[] byteDataParams = Encoding.UTF8.GetBytes("speaker=nara&volume=0&speed=0&pitch=0&format=mp3&text=" + text);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteDataParams.Length;
Stream st = request.GetRequestStream();
st.Write(byteDataParams, 0, byteDataParams.Length);
st.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string status = response.StatusCode.ToString();
Console.WriteLine("status="+ status);
using (Stream output = File.OpenWrite("c:/tts.mp3"))
using (Stream input = response.GetResponseStream())
{
input.CopyTo(output);
}
Console.WriteLine("c:/tts.mp3 was created");
}
}
}
curl "https://naveropenapi.apigw.ntruss.com/tts-premium/v1/tts" \
-d "speaker=nara&volume=0&speed=0&pitch=0&format=mp3&text=Nice to meet you." \
-H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" \
-H "X-NCP-APIGW-API-KEY-ID: {Client ID value issued upon registering the application}" \
-H "X-NCP-APIGW-API-KEY: {Client secret value issued upon registering the application}" -v \
> out.mp3
Error codes
HttpStatusCode | ErrorCode | ErrorMessage | Description |
---|---|---|---|
400 | VS01 | speaker parameter is needed. | Missing speaker parameter |
400 | VS02 | Unsupported speaker. | Unsupported speaker parameter |
400 | VS03 | Speed parameter is needed. | Missing speed parameter |
400 | VS04 | Unsupported speed. | Unsupported speed parameter |
400 | VS05 | text parameter is needed. | Text parameter is missing |
400 | VS06 | text parameter exceeds max length. | Text parameter exceeds the maximum number of characters |
400 | VS07 | Unsupported volume. | Unsupported volume |
400 | VS08 | Unsupported pitch. | Unsupported pitch |
400 | VS09 | Unsupported alpha. | Unsupported tone |
400 | VS10 | Text parameter check. | Existence of text that cannot be synthesized |
400 | VS11 | Unsupported format. | Unsupported format |
400 | VS14 | Unsupported emotion value. | Unsupported emotion parameter |
400 | VS18 | Text parameter exceeds max length per sentence. | Exceeds the maximum length per sentence (200 characters) |
400 | VS19 | Unsupported emotion-strength. | Unsupported intensity of emotion |
400 | VS26 | Failed to make tts. | TTS creation failed |
400 | VS46 | Unsupported end-pitch. | Unsupported end-pitch processing |
500 | VS99 | Internal server error | Occurrence of internal server error Requires customer support |
Was this article helpful?