tts (Premium)
    • PDF

    tts (Premium)

    • PDF

    Article Summary

    개요

    CLOVA Voice - Premium API는 음성으로 변환할 텍스트와 음색, 속도, 감정 등을 파라미터로 입력받은 후 음성을 합성하여 그 결과를 반환하는 HTTP 기반의 REST API입니다.

    요청

    curl -i -X POST \
    	-H "Content-Type:application/x-www-form-urlencoded" \
    	-H "X-NCP-APIGW-API-KEY-ID:{애플리케이션 등록 시 발급받은 client id값}" \
    	-H "X-NCP-APIGW-API-KEY:{애플리케이션 등록 시 발급받은 client secret값}" \
    	-d 'speaker={목소리 종류}&text={텍스트}&volume={볼륨}&speed={음성 재생 속도}&pitch={피치}' \
     'https://naveropenapi.apigw.ntruss.com/tts-premium/v1/tts'
    

    요청 파라미터

    파라미터 이름타입설명기본값필수 여부
    speakerstring음성 합성에 사용할 목소리 종류
    • nara : 아라: 한국어, 여성 음색
    • nara_call : 아라(상담원): 한국어, 여성 음색
    • nminyoung : 민영: 한국어, 여성 음색
    • nyejin : 예진: 한국어, 여성 음색
    • mijin : 미진: 한국어, 여성 음색
    • jinho : 진호: 한국어, 남성 음색
    • clara : 클라라: 영어, 여성 음색
    • matt : 매트: 영어, 남성 음색
    • shinji : 신지: 일본어, 남성 음색
    • meimei : 메이메이: 중국어, 여성 음색
    • liangliang : 량량: 중국어, 남성 음색
    • jose : 호세: 스페인어, 남성 음색
    • carmen : 카르멘: 스페인어, 여성 음색
    • nminsang : 민상: 한국어, 남성 음색
    • nsinu : 신우: 한국어, 남성 음색
    • nhajun : 하준: 한국어, 아동 음색 (남)
    • ndain : 다인: 한국어, 아동 음색 (여)
    • njiyun : 지윤: 한국어, 여성 음색
    • nsujin : 수진: 한국어, 여성 음색
    • njinho : 진호: 한국어, 남성 음색
    • njihun : 지훈: 한국어, 남성 음색
    • njooahn : 주안: 한국어, 남성 음색
    • nseonghoon : 성훈: 한국어, 남성 음색
    • njihwan : 지환: 한국어, 남성 음색
    • nsiyoon : 시윤: 한국어, 남성 음색
    • ngaram : 가람: 한국어, 아동 음색 (여)
    • ntomoko : 토모코: 일본어, 여성 음색
    • nnaomi : 나오미: 일본어, 여성 음색
    • dnaomi_joyful : 나오미(기쁨): 일본어, 여성 음색
    • dnaomi_formal : 나오미(뉴스): 일본어, 여성 음색
    • driko : 리코: 일본어, 여성 음색
    • deriko : 에리코: 일본어, 여성 음색
    • nsayuri : 사유리: 일본어, 여성 음색
    • ngoeun : 고은: 한국어, 여성 음색
    • neunyoung : 은영: 한국어, 여성 음색
    • nsunkyung : 선경: 한국어, 여성 음색
    • nyujin : 유진: 한국어, 여성 음색
    • ntaejin : 태진: 한국어, 남성 음색
    • nyoungil : 영일: 한국어, 남성 음색
    • nseungpyo : 승표: 한국어, 남성 음색
    • nwontak : 원탁: 한국어, 남성 음색
    • dara_ang : 아라(화남):  한국어, 여성 음색
    • nsunhee : 선희:  한국어, 여성 음색
    • nminseo : 민서:  한국어, 여성 음색
    • njiwon : 지원:  한국어, 여성 음색
    • nbora : 보라:  한국어, 여성 음색
    • njonghyun: 종현:  한국어, 남성 음색
    • njoonyoung : 준영:  한국어, 남성 음색
    • njaewook: 재욱:  한국어, 남성 음색
    • danna: 안나: 영어, 여성 음색
    • djoey: 조이: 영어, 여성 음색
    • dhajime: 하지메: 일본어, 남성 음색
    • ddaiki: 다이키: 일본어, 남성 음색
    • dayumu: 아유무: 일본어, 남성 음색
    • dmio: 미오: 일어, 여성 음색
    • chiahua: 차화: 대만어, 여성 음색
    • kuanlin: 관린: 대만어, 남성 음색
    • nes_c_hyeri: 혜리: 한국어, 여성 음색
    • nes_c_sohyun: 소현: 한국어, 여성 음색
    • nes_c_mikyung: 미경: 한국어, 여성 음색
    • nes_c_kihyo: 기효: 한국어, 남성 음색
    • ntiffany: 기서: 한국어, 여성 음색
    • napple: 늘봄: 한국어, 여성 음색
    • njangj: 드림: 한국어, 여성 음색
    • noyj: 봄달: 한국어, 여성 음색
    • neunseo: 은서: 한국어, 여성 음색
    • nheera: 희라: 한국어, 여성 음색
    • nyoungmi: 영미: 한국어, 여성 음색
    • nnarae: 나래: 한국어, 여성 음색
    • nyeji: 예지: 한국어, 여성 음색
    • nyuna: 유나: 한국어, 여성 음색
    • nkyunglee: 경리: 한국어, 여성 음색
    • nminjeong: 민정: 한국어, 여성 음색
    • nihyun: 이현: 한국어, 여성 음색
    • nraewon: 래원: 한국어, 남성 음색
    • nkyuwon : 규원: 한국어, 남성 음색
    • nkitae: 기태: 한국어, 남성 음색
    • neunwoo: 은우: 한국어, 남성 음색
    • nkyungtae: 경태: 한국어, 남성 음색
    • nwoosik: 우식: 한국어, 남성 음색
    • vara: 아라(pro): 한국어, 여성 음색
    • vmikyung: 미경(pro): 한국어, 여성 음색
    • vdain: 다인(pro): 한국어, 여성 음색
    • vyuna: 유나(pro): 한국어, 여성 음색
    • vhyeri: 혜리(pro): 한국어, 여성 음색
    • dara-danna: 아라&안나: 한국어+영어(미국), 여성 음색
    • dsinu-matt: 신우&매트: 한국어+영어(미국), 남성 음색
    • nsabina : 마녀 사비나: 한국어, 여성 음색
    • nmammon : 악마 마몬: 한국어, 남성 음색
    • nmeow : 야옹이: 한국어, 아동 음색 (여)
    • nwoof : 멍멍이: 한국어, 아동 음색 (남)
    • nreview : 박리뷰: 한국어, 남성 음색
    • nyounghwa : 정영화: 한국어, 여성 음색
    • nmovie : 최무비: 한국어, 남성 음색
    • nsangdo : 상도: 한국어, 남성 음색
    • nshasha : 샤샤: 한국어, 여성 음색
    • nian : 이안: 한국어, 남성 음색
    • ndonghyun : 동현: 한국어, 남성 음색
    • vian : 이안(pro): 한국어, 남성 음색
    • vdonghyun : 동현(pro): 한국어, 남성 음색
    • dsayuri : 사유리: 일본어, 여성 음색
    • dtomoko : 토모코: 일본어, 여성 음색
    • dnaomi : 나오미: 일본어, 여성 음색
    • vgoeun : 고은(pro): 한국어, 여성 음색
    • vdaeseong : 대성(pro): 한국어, 남성 음색
    • ngyeongjun : 경준: 한국어, 남성 음색
    • ndaeseong : 대성: 한국어, 남성 음색
    • njonghyeok : 종혁: 한국어, 남성 음색
    없음Y
    textstring- 음성 합성할 문장
    - UTF-8 인코딩된 텍스트만 지원
    - 최대 2,000자까지 음성 합성
    - 기호나 괄호 안의 텍스트는 읽지 않음
    없음Y
    volumeinteger- 음성 볼륨
    - (-)5에서 5 사이의 정수 값
    - (-)5이면 0.5배 낮은 볼륨, 5이면 1.5배 더 큰 볼륨, 0이면 정상 볼륨로 음성 합성
    0N
    speedinteger- 음성 속도
    - (-)5에서 5 사이의 정수 값
    - (-)5이면 2배 빠른 속도, 5이면 0.5배 더 느린 속도, 0이면 정상 속도로 음성 합성
    0N
    pitchinteger- 음성 피치
    - (-)5에서 5 사이의 정수 값
    - (-)5이면 1.2배 높은 피치, 5이면 0.8배 더 낮은 피치, 0이면 정상 피치로 음성 합성
    0N
    emotioninteger- 음성 감정
    - 0에서 3 사이의 정수 값
    - 지원 speaker : nara, vara, vmikyung, vdain, vyuna(단, nara 는 3: 분노 미지원)
  • 0: 중립
  • 1: 슬픔
  • 2: 기쁨
  • 3: 분노
  • 0N
    emotion-strengthinteger- 감정의 강도
    - 지원 speaker : vara, vmikyung, vdain, vyuna(nara 미지원)
  • 0: 약함
  • 1: 보통
  • 2: 강함
  • 1N
    formatstring- 음성 포맷
    - mp3 또는 wav
    mp3N
    sampling-rateinteger- 샘플링 레이트
    - wav 포맷일 때만 지원하며, mp3 포맷은 24000에서 변경 불가
    단, mijin은 16000만 지원
  • 8000
  • 16000
  • 24000
  • 48000
  • 24000N
    alphainteger- 음색
    - (-)5에서 5 사이의 정수값
    - 0보다 크면 높은 음색, 0보다 작으면 낮은 음색
    0N
    end-pitchinteger- 끝음 처리
    - (-)5에서 5 사이의 정수값
    0보다 크면 문장 끝을 올리고, 0보다 작으면 문장 끝을 내림
    - 지원 speaker : 'd'로 시작하는 speaker(ex.dara, danna..)와 clara, matt, meimei, liangliang, chiahua, kuanlin, carmen, jose
    0N

    요청 헤더

    헤더명설명
    X-NCP-APIGW-API-KEY-ID앱 등록 시 발급받은 Client ID
    X-NCP-APIGW-API-KEY-ID:{Client ID}
    X-NCP-APIGW-API-KEY앱 등록 시 발급 받은 Client Secret
    X-NCP-APIGW-API-KEY:{Client Secret}
    Content-Typeapplication/x-www-form-urlencoded로 고정
    Content-Type: application/x-www-form-urlencoded

    요청 바디

    • 해당 API 는 요청 바디를 필요로 하지 않습니다.

    응답

    응답 바디

    • MP3 또는 WAV 바이너리 데이터

    예시

    요청 예시

    curl -i -X POST \
    	-H "Content-Type:application/x-www-form-urlencoded" \
    	-H "X-NCP-APIGW-API-KEY-ID:{애플리케이션 등록 시 발급받은 client id값}" \
    	-H "X-NCP-APIGW-API-KEY:{애플리케이션 등록 시 발급받은 client secret값}" \
    	-d 'speaker=nara&text=만나서 반갑습니다&volume=0&speed=0&pitch=0&format=mp3' \
     'https://naveropenapi.apigw.ntruss.com/tts-premium/v1/tts'
    

    응답 예시

    [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]
    {MP3 형식의 바이너리 데이터}
    

    API 예제

    // 네이버 음성합성 Open API 예제
    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";//애플리케이션 클라이언트 아이디값";
            String clientSecret = "YOUR_CLIENT_SECRET";//애플리케이션 클라이언트 시크릿값";
            try {
                String text = URLEncoder.encode("만나서 반갑습니다.", "UTF-8"); // 13자
                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) { // 정상 호출
                    InputStream is = con.getInputStream();
                    int read = 0;
                    byte[] bytes = new byte[1024];
                    // 랜덤한 이름으로 mp3 파일 생성
                    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 {  // 오류 발생
                    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);
            }
        }
    }
    
    // 네이버 음성합성 Open API 예제
    <?php
      $client_id = "YOUR_CLIENT_ID";
      $client_secret = "YOUR_CLIENT_SECRET";
      $encText = urlencode("반갑습니다.");
      $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'>TTS재생</a>";
      } else {
        echo "Error 내용:".$response;
      }
    ?>
    
    // 네이버 음성합성 Open API 예제
    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: '좋은 하루 되세요', 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); // file로 출력
      _req.pipe(res); // 브라우저로 출력
    });
    app.listen(3000, function() {
      console.log('http://127.0.0.1:3000/tts app listening on port 3000!');
    });
    
    // 네이버 음성합성 Open API 예제
    import os
    import sys
    import urllib.request
    client_id = "YOUR_CLIENT_ID"
    client_secret = "YOUR_CLIENT_SECRET"
    encText = urllib.parse.quote("반갑습니다 네이버")
    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("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" # 애플리케이션 클라이언트 아이디값"
    client_secret = "YOUR_CLIENT_SECRET" # 애플리케이션 클라이언트 시크릿값"
    text = unicode("반갑습니다 네이버") # 음성 합성할 문장
    speaker = "nara" # 음성 합성에 사용할 목소리 종류
    speed = "0" # 음성 재생 속도
    volume = "0" # 음성 볼륨
    pitch = "0" # 음성 피치
    fmt = "mp3" # 음성 포멧
    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)
    
    
    // 네이버 음성합성 Open API 예제
    using System;
    using System.Net;
    using System.Text;
    using System.IO;
    
    namespace NaverAPI_Guide
    {
        public class APIExamTTS
        {
            static void Main(string[] args)
            {
                string text = "좋은 하루 되세요."; // 음성합성할 문자값
                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=만나서 반갑습니다." \
    	-H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" \
    	-H "X-NCP-APIGW-API-KEY-ID: {애플리케이션 등록 시 발급받은 client id 값}" \
    	-H "X-NCP-APIGW-API-KEY: {애플리케이션 등록 시 발급받은 client secret 값}" -v \
    		> out.mp3
    

    오류 코드

    HttpStatusCodeErrorCodeErrorMessageDescription
    400VS01speaker parameter is needed.speaker 파라미터 누락
    400VS02Unsupported speaker.지원하지 않는 speaker 파라미터
    400VS03Speed parameter is needed.speed 파라미터 누락
    400VS04Unsupported speed.지원하지 않는 speed 파라미터
    400VS05text parameter is needed.text 파라미터 누락
    400VS06text parameter exceeds max length.text 파라미터 입력 글자수 초과
    400VS07Unsupported volume.지원하지 않는 볼륨
    400VS08Unsupported pitch.지원하지 않는 피치
    400VS09Unsupported alpha.지원하지 않는 음색
    400VS10Text parameter check.합성할 수 없는 text 존재
    400VS11Unsupported format.지원하지 않는 포맷
    400VS14Unsupported emotion value.지원하지 않는 감정 파라미터
    400VS18Text parameter exceeds max length per sentence.문장당 최대 길이(200자) 초과
    400VS19Unsupported emotion-strength.지원하지 않는 감정 강도
    400VS26Failed to make tts.TTS 생성 실패
    400VS46Unsupported end-pitch.지원하지 않는 끝음 처리
    500VS99Internal server error서버 내부 오류 발생
    고객지원 문의 필요

    이 문서가 도움이 되었습니까?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.