google tts
1.0.0
node.js 용 Google TTS (텍스트 음성)
$ npm install --save google-tts-api
$ npm install -D typescript @types/node # Only for TypeScript Changelog를 참조하십시오.
| 방법 | 옵션 (모든 선택 사항) | 반환 유형 | 긴 텍스트를 처리합니다 |
|---|---|---|---|
getAudioUrl | lang , slow , host | string | |
getAudioBase64 | lang , slow , host , timeout | Promise<string> | |
getAllAudioUrls | lang , slow , host , splitPunct | { shortText: string; url: string; }[] | ✅ |
getAllAudioBase64 | lang , slow , host , timeout , splitPunct | Promise<{ shortText: string; base64: string; }[]> | ✅ |
| 옵션 | 유형 | 기본 | 설명 |
|---|---|---|---|
lang | string | en | https://cloud.google.com/speech/docs/languages에서 모든 언어 코드를 참조하십시오 |
slow | boolean | 거짓 | slow 설정되면 느린 오디오 속도를 사용하십시오 true |
host | string | https://translate.google.com | 해당 지역에서 기본 호스트가 작동하지 않으면 host 변경할 수 있습니다 (예 : https://translate.google.com.cn). |
timeout | number | 10000 (MS) | ( getAudioBase64 및 getAllAudioBase64 에만 해당) HTTP 요청에 대한 시간 초과를 설정하십시오. |
splitPunct | string | ( getAllAudioUrls 및 getAllAudioBase64 에만 해당) 긴 텍스트를 짧은 텍스트로 나누기 위해 문장 부호를 설정하십시오. (예 : ",") |
getAudioUrl(text, [option]) import * as googleTTS from 'google-tts-api' ; // ES6 or TypeScript
const googleTTS = require ( 'google-tts-api' ) ; // CommonJS
// get audio URL
const url = googleTTS . getAudioUrl ( 'Hello World' , {
lang : 'en' ,
slow : false ,
host : 'https://translate.google.com' ,
} ) ;
console . log ( url ) ; // https://translate.google.com/translate_tts?...getAudioBase64(text, [option]) import * as googleTTS from 'google-tts-api' ; // ES6 or TypeScript
const googleTTS = require ( 'google-tts-api' ) ; // CommonJS
// get base64 text
googleTTS
. getAudioBase64 ( 'Hello World' , {
lang : 'en' ,
slow : false ,
host : 'https://translate.google.com' ,
timeout : 10000 ,
} )
. then ( console . log ) // base64 text
. catch ( console . error ) ;getAllAudioUrls(text, [option]) (200 자 미만의 텍스트의 경우) import * as googleTTS from 'google-tts-api' ; // ES6 or TypeScript
const googleTTS = require ( 'google-tts-api' ) ; // CommonJS
const results = googleTTS . getAllAudioUrls ( 'LONG_TEXT_...' , {
lang : 'en' ,
slow : false ,
host : 'https://translate.google.com' ,
splitPunct : ',.?' ,
} ) ;
console . log ( results ) ;
// [
// { shortText: '...', url: '...' },
// { shortText: '...', url: '...' },
// ...
// ];getAllAudioBase64(text, [option]) (200 자 미만의 텍스트의 경우) import * as googleTTS from 'google-tts-api' ; // ES6 or TypeScript
const googleTTS = require ( 'google-tts-api' ) ; // CommonJS
googleTTS
. getAllAudioBase64 ( 'LONG_TEXT_...' , {
lang : 'en' ,
slow : false ,
host : 'https://translate.google.com' ,
timeout : 10000 ,
splitPunct : ',.?' ,
} )
. then ( console . log )
// [
// { shortText: '...', base64: '...' },
// { shortText: '...', base64: '...' },
// ...
// ];
. catch ( console . error ) ;더 많은 예
MIT