Skip to content

Instantly share code, notes, and snippets.

@thejungwon
Created October 5, 2020 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thejungwon/6f171a22df45f97329515e1fadbf6f0b to your computer and use it in GitHub Desktop.
Save thejungwon/6f171a22df45f97329515e1fadbf6f0b to your computer and use it in GitHub Desktop.
import os
import sys
import urllib.request
client_id = "<YOUR_CLIENT_ID>"
client_secret = "<YOUR_CLIENT_SECRET>"
encText = urllib.parse.quote(extracted_text)
data = "speaker=mijin&speed=0&text=" + encText;
url = "https://naveropenapi.apigw.ntruss.com/voice/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment