google tts
1.0.0
Google TTS (text-to-speech) สำหรับ node.js
$ 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 | 10,000 (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 ) ;ตัวอย่างเพิ่มเติม
มิกซ์