simple-tts-mp3
Advanced tools
Comparing version 1.0.7 to 1.1.0
39
index.js
@@ -12,2 +12,4 @@ const googleTTS = require('google-tts-api'); | ||
* | ||
* @returns {Promise<string>} A promise that resolves with the file path when the audio file is created. | ||
* | ||
* - Supported Languages | ||
@@ -71,15 +73,9 @@ * - af - Afrikaans | ||
*/ | ||
function createAudioFile(text, fileName, language = 'en') { | ||
async function createAudioFile(text, fileName, language = 'en') { | ||
const filePath = path.resolve(`${fileName}.mp3`); | ||
googleTTS.getAllAudioBase64(text, { lang: language }) | ||
.then((result) => { | ||
const buffers = result.map(result => Buffer.from(result.base64, 'base64')); | ||
const finalBuffer = Buffer.concat(buffers); | ||
fs.writeFileSync(filePath, finalBuffer); | ||
console.log(`Audio file ${filePath} created successfully`); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
}); | ||
const base64Array = await googleTTS.getAllAudioBase64(text, { lang: language }); | ||
const buffers = base64Array.map(result => Buffer.from(result.base64, 'base64')); | ||
const finalBuffer = Buffer.concat(buffers); | ||
await fs.promises.writeFile(filePath, finalBuffer); | ||
return filePath; | ||
} | ||
@@ -92,2 +88,5 @@ | ||
* @param {string} [language='en'] The language of the text (ISO 639-1 code) (optional). | ||
* | ||
* @returns {Promise<Buffer>} A promise that resolves with the mp3 audio buffer. | ||
* | ||
* - Supported Languages | ||
@@ -150,15 +149,11 @@ * - af - Afrikaans | ||
* - vi - Vietnamese | ||
* | ||
* @returns {Promise<Buffer>} A promise that resolves with the mp3 audio buffer. | ||
* | ||
*/ | ||
function getAudioBuffer(text, language = 'en') { | ||
return googleTTS.getAllAudioBase64(text, { lang: language }) | ||
.then((result) => { | ||
const buffers = result.map(result => Buffer.from(result.base64, 'base64')); | ||
const finalBuffer = Buffer.concat(buffers); | ||
return finalBuffer; | ||
}); | ||
async function getAudioBuffer(text, language = 'en') { | ||
const base64Array = await googleTTS.getAllAudioBase64(text, { lang: language }); | ||
const buffers = base64Array.map(result => Buffer.from(result.base64, 'base64')); | ||
const finalBuffer = Buffer.concat(buffers); | ||
return finalBuffer; | ||
} | ||
module.exports = { createAudioFile, getAudioBuffer }; |
{ | ||
"name": "simple-tts-mp3", | ||
"version": "1.0.7", | ||
"version": "1.1.0", | ||
"description": "Converts text to mp3 audio using google-tts-api, it hasn't a limit", | ||
@@ -12,3 +12,3 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "git+https://github.com/eliangerard/text-to-mp3.git" | ||
"url": "git+https://github.com/eliangerard/simple-tts-mp3.git" | ||
}, | ||
@@ -24,5 +24,5 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/eliangerard/text-to-mp3/issues" | ||
"url": "https://github.com/eliangerard/simple-tts-mp3/issues" | ||
}, | ||
"homepage": "https://github.com/eliangerard/text-to-mp3#readme", | ||
"homepage": "https://github.com/eliangerard/simple-tts-mp3#readme", | ||
"dependencies": { | ||
@@ -29,0 +29,0 @@ "google-tts-api": "^2.0.2" |
@@ -8,3 +8,3 @@ # simple-tts-mp3 package | ||
| ------------------- | ---------------------------------------- | --------------------------------------------------- | | ||
| createAudioFile | text, fileName, [language = 'en'] | Creates an mp3 audio file from text. | | ||
| createAudioFile | text, fileName, [language = 'en'] | Creates an mp3 audio file from text and returns its final path - Promise (String) | | ||
| getAudioBuffer | text, [language = 'en'] | Creates an mp3 audio buffer from text and returns it - Promise (Buffer) | | ||
@@ -32,7 +32,9 @@ | ||
// Creates an "output.mp3" audio file with Spanish text | ||
createAudioFile('Hola, ¿Cómo estás?', 'output', 'es'); | ||
// Creates an "output.mp3" audio file with Spanish text and promise resolved | ||
createAudioFile('Hola, ¿Cómo estás?', 'output', 'es').then((filepath) => { | ||
console.log(filepath); | ||
}); | ||
// Creates an "output.mp3" audio file with Spanish text inside the "audios" folder | ||
createAudioFile('Todo bien, gracias', './audios/output', 'es'); | ||
// Creates an "output.mp3" audio file with Spanish text inside the "audios" folder and awaits filepath | ||
const filepath = await createAudioFile('Todo bien, gracias', './audios/output', 'es'); | ||
``` | ||
@@ -49,2 +51,5 @@ + getAudioBuffer( text, language = 'en') | ||
}); | ||
// Creates an MP3 audio buffer with default English text and awaits it | ||
const buffer = await getAudioBuffer('Hi, How are you?'); | ||
``` |
@@ -10,2 +10,4 @@ declare module 'simple-tts-mp3' { | ||
* | ||
* @returns {Promise<string>} A promise that resolves with the file path when the audio file is created. | ||
* | ||
* - Supported Languages | ||
@@ -69,3 +71,3 @@ * - af - Afrikaans | ||
*/ | ||
export function createAudioFile(text: string, fileName: string, language?: string): void; | ||
export function createAudioFile(text: string, fileName: string, language?: string): Promise<string>; | ||
@@ -77,2 +79,5 @@ /** | ||
* @param {string} [language='en'] The language of the text (ISO 639-1 code) (optional). | ||
* | ||
* @returns {Promise<Buffer>} A promise that resolves with the mp3 audio buffer. | ||
* | ||
* - Supported Languages | ||
@@ -135,7 +140,4 @@ * - af - Afrikaans | ||
* - vi - Vietnamese | ||
* | ||
* @returns {Promise<Buffer>} A promise that resolves with the mp3 audio buffer. | ||
* | ||
*/ | ||
export function getAudioBuffer(text: string, language?: string): Promise<Buffer>; | ||
} |
@@ -1,74 +0,9 @@ | ||
const { createAudioFile, getAudioBuffer } = require('../index.js'); | ||
const { createAudioFile, getAudioBuffer } = require("../index.js"); | ||
const text = 'Hola mundo'; | ||
const fileName = 'output'; | ||
createAudioFile("Hello World!", "./test/test", "en").then((filePath) => { | ||
console.log(filePath); | ||
}); | ||
createAudioFile(text, fileName, 'es'); | ||
// const languageCodes = [ | ||
// 'af', 'sq', 'de', 'ar', 'bn', 'my', 'bs', 'bg', 'km', 'kn', 'ca', 'cs', 'zh', 'zh-TW', 'si', 'ko', 'hr', 'da', 'sk', 'es', 'et', 'fi', 'fr', 'el', 'gu', 'he', 'hi', 'nl', 'hu', 'id', 'en', 'is', 'it', 'ja', 'jv', 'la', 'lv', 'ml', 'ms', 'mr', 'ne', 'no', 'pl', 'pt', 'ro', 'ru', 'sr', 'sw', 'sv', 'su', 'tl', 'th', 'ta', 'te', 'tr', 'uk', 'ur', 'vi' | ||
// ]; | ||
// const languages = [ | ||
// {"language": "af", "hello": "hallo"}, | ||
// {"language": "sq", "hello": "përshëndetje"}, | ||
// {"language": "de", "hello": "hallo"}, | ||
// {"language": "ar", "hello": "مرحبا"}, | ||
// {"language": "bn", "hello": "হ্যালো"}, | ||
// {"language": "my", "hello": "ဟယ်လို"}, | ||
// {"language": "bs", "hello": "zdravo"}, | ||
// {"language": "bg", "hello": "здравейте"}, | ||
// {"language": "km", "hello": "សួស្តី"}, | ||
// {"language": "kn", "hello": "ಹಲೋ"}, | ||
// {"language": "ca", "hello": "hola"}, | ||
// {"language": "cs", "hello": "ahoj"}, | ||
// {"language": "zh", "hello": "你好"}, | ||
// {"language": "zh-TW", "hello": "你好"}, | ||
// {"language": "si", "hello": "හෙලෝ"}, | ||
// {"language": "ko", "hello": "안녕하세요"}, | ||
// {"language": "hr", "hello": "zdravo"}, | ||
// {"language": "da", "hello": "hej"}, | ||
// {"language": "sk", "hello": "ahoj"}, | ||
// {"language": "es", "hello": "hola"}, | ||
// {"language": "et", "hello": "tere"}, | ||
// {"language": "fi", "hello": "hei"}, | ||
// {"language": "fr", "hello": "salut"}, | ||
// {"language": "el", "hello": "γεια σου"}, | ||
// {"language": "gu", "hello": "હેલો"}, | ||
// {"language": "he", "hello": "שלום"}, | ||
// {"language": "hi", "hello": "नमस्ते"}, | ||
// {"language": "nl", "hello": "hallo"}, | ||
// {"language": "hu", "hello": "szia"}, | ||
// {"language": "id", "hello": "halo"}, | ||
// {"language": "en", "hello": "hello"}, | ||
// {"language": "is", "hello": "halló"}, | ||
// {"language": "it", "hello": "ciao"}, | ||
// {"language": "ja", "hello": "こんにちは"}, | ||
// {"language": "jv", "hello": "halo"}, | ||
// {"language": "la", "hello": "salve"}, | ||
// {"language": "lv", "hello": "sveiki"}, | ||
// {"language": "ml", "hello": "ഹലോ"}, | ||
// {"language": "ms", "hello": "hai"}, | ||
// {"language": "mr", "hello": "हॅलो"}, | ||
// {"language": "ne", "hello": "नमस्कार"}, | ||
// {"language": "no", "hello": "hallo"}, | ||
// {"language": "pl", "hello": "cześć"}, | ||
// {"language": "pt", "hello": "olá"}, | ||
// {"language": "ro", "hello": "salut"}, | ||
// {"language": "ru", "hello": "привет"}, | ||
// {"language": "sr", "hello": "здраво"}, | ||
// {"language": "sw", "hello": "hujambo"}, | ||
// {"language": "sv", "hello": "hej"}, | ||
// {"language": "su", "hello": "halo"}, | ||
// {"language": "tl", "hello": "kamusta"}, | ||
// {"language": "th", "hello": "สวัสดี"}, | ||
// {"language": "ta", "hello": "வணக்கம்"}, | ||
// {"language": "te", "hello": "హలో"}, | ||
// {"language": "tr", "hello": "merhaba"}, | ||
// {"language": "uk", "hello": "привіт"}, | ||
// {"language": "ur", "hello": "ہیلو"}, | ||
// {"language": "vi", "hello": "xin chào"} | ||
// ] | ||
// languages.forEach( ({language, hello}) => { | ||
// createAudioFile(hello, "./lang-"+language, language); | ||
// }) | ||
getAudioBuffer("Hello World!", "en").then((buffer) => { | ||
console.log(buffer); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53
11729
292