Pricing 
API Pricing

Try For Free Now

Dark

Light

TEXT TO SPEECH
Speech Synthesis
Convert text to a speech synthesis file.
Endpoint
Request details
POST
https://translate.rozetta-api.io/api/v1/translate/tts
Header
Header
Description
Content-Type
application/json
accessKey, nonce, signature
Please refer to the authentication section.
Body
Key
Required
Description
targetLang
O
The language of the text. Please use the ISO 639-1 code. English, Japanese and Chinese are supported now.
text
O
Original text. Specify the text to be translated, up to 8000 bites(about 2000 Chinese characters). This field is required.
contractId
Contract ID. For user who has one contract, the field can be omitted. For user who has two or more contracts, it's required to specify the contractId. (e.g. User who has a Text translation contract and a Speech translation contract, has to specify the contract ID)
Response
Key
Description
N/A
The synthesized speech file in WAV format.

api/v1/translate/tts
Convert text to speech synthesis file.
JavaScript
C#
const fs = require('fs');
const https = require('https');
const crypto = require('crypto');

const authUtils = require('./utils/auth-utils');

const serverConfig = {
 protocol: 'https:',
 hostname: 'translate.rozetta-api.io',
 port: 443
};
const authConfig = {
 accessKey: 'ACCESS_KEY',
 secretKey: 'SECRET_KEY',
 nonce: Date.now().toString()
};
const data = {
 text: 'こんにちは、いい天気ですね。',
 targetLang: 'ja',
 contractId: 'your contractId'
};
const speechFile = 'speech.wav';

const getSpeechResult = (serverConfig, authConfig, data) => {
 const path = '/api/v1/translate/tts';
 const signature = authUtils.generateSignature(
   path,
   authConfig.secretKey,
   authConfig.nonce
 );
 const requestOptions = {
   protocol: serverConfig.protocol,
   host: serverConfig.hostname,
   port: serverConfig.port,
   method: 'POST',
   path,
   headers: {
     accessKey: authConfig.accessKey,
     signature,
     nonce: authConfig.nonce,
     'Content-Type': 'application/json'
   }
 };

 return new Promise((resolve, reject) => {
   const request = https.request(requestOptions, (response) => {
     const writeStream = fs.createWriteStream(speechFile);
     response.pipe(writeStream);
     response.on('close', () => {
       resolve();
     });
   });
   request.on('error', (error) => {
     reject(error);
   });
   request.write(JSON.stringify(data));
   request.end();
 });
};

const main = async () => {
 try {
   await getSpeechResult(serverConfig, authConfig, data);
   console.log('Speech file downloaded to:');
   console.log(speechFile);
 } catch (error) {
   console.error(error);
 }
};

main();
About the authentication, please refer to the authentication section.
You can get a full version of sample codes here
©️ 2019 Rozetta API  ・  Powered by Rozetta

Rozetta Corp.

^