google translate tts
1.0.0
هذه الحزمة مخصصة لاستخدام Google Translate لإنشاء مقاطع صوتية في Node JS.
تم تحديث هذه المكتبة للعمل مع التغييرات الجديدة على واجهة برمجة تطبيقات الترجمة التي أدخلتها Google في نوفمبر 2020.
خليفة روحي لـ Google-TTS-API الذي عمل مع API التترجيم السابق.
npm install google-translate-tts
أو
yarn add google-translate-tts
ابحث عن صوت لاستخدامه:
const tts = require ( 'google-translate-tts' ) ;
// lookup by name
const voice = tts . voices . findByName ( 'English (United States)' ) ;
// lookup by code
const voice = tts . voices . findByCode ( 'en-US' ) ;
// an array of all voices
console . log ( tts . voices ) ;
/* Voice example:
* {
* code: 'en-US',
* name: 'English (United States)'
* }
*/قم بتنزيل مقطع صوتي:
const fs = require ( 'fs' ) ;
const tts = require ( 'google-translate-tts' ) ;
// notice that `tts.synthesize` returns a Promise<Buffer>
const saveFile = async ( ) => {
const buffer = await tts . synthesize ( {
text : 'Hello, world!' ,
voice : 'en-US' ,
slow : false // optional
} ) ;
fs . writeFileSync ( 'hello-world.mp3' , buffer ) ;
} ;
saveFile ( ) ;