Created
June 20, 2021 06:30
-
-
Save hmmhmmhm/67a6a79dcd8a6dbc52b4a4aab78827e3 to your computer and use it in GitHub Desktop.
구글 TTS API 자바스크립트 & 타입스크립트 예제 (Google TTS API Javascript & Typescript Usage)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// How To Authentication: https://cloud.google.com/docs/authentication/getting-started#auth-cloud-implicit-nodejs | |
import textToSpeech from '@google-cloud/text-to-speech' | |
import fs from 'fs' | |
import util from 'util' | |
// Creates a client | |
const client = new textToSpeech.TextToSpeechClient() | |
const getTTSContent = async (props: { | |
text: string | |
languageCode: string | |
voiceName: string | |
}) => { | |
// Performs the text-to-speech request | |
const [response] = await client.synthesizeSpeech({ | |
input: { text: props.text }, | |
voice: { languageCode: props.languageCode, name: props.voiceName }, | |
audioConfig: { audioEncoding: 'MP3' }, | |
}) | |
return response.audioContent | |
} | |
const main = async () => { | |
const audioContent = await getTTSContent({ | |
text: `동해물과 백두산이 마르고 닳도록`, | |
languageCode: `ko-KR`, | |
voiceName: `ko-KR-Wavenet-A`, | |
}) | |
const writeFile = util.promisify(fs.writeFile) | |
if (audioContent) await writeFile('output.mp3', audioContent, 'binary') | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment