-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ui improvements and add txt2audio lib to generate animals names
- Loading branch information
1 parent
8980957
commit cd5a091
Showing
56 changed files
with
154 additions
and
315 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,18 @@ | ||
const textToSpeech = require('@google-cloud/text-to-speech') | ||
const fs = require('fs') | ||
const util = require('util') | ||
const animals = require('../animals.json') | ||
const report = require('yurnalist') | ||
const Txt2Audio = require('txt2audio') | ||
const path = require('path') | ||
const ffmpeg = require('fluent-ffmpeg') | ||
|
||
const client = new textToSpeech.TextToSpeechClient() | ||
|
||
const convertAudioToOgg = async (animal, folder) => { | ||
return new Promise(async (resolve, reject) => { | ||
return ffmpeg() | ||
.input(`${folder}/${animal}.mp3`) | ||
.toFormat('ogg') | ||
.output(`${folder}/${animal}.ogg`) | ||
.on('end', resolve) | ||
.on('error', reject) | ||
.run() | ||
}) | ||
} | ||
|
||
const generateAudioFile = async animal => { | ||
const text = animal | ||
const folder = path.resolve(__dirname, '..', '..', 'audio', 'names') | ||
const request = { | ||
input: { text }, | ||
voice: { languageCode: 'en-US-Standard-C', ssmlGender: 'FEMALE' }, | ||
audioConfig: { audioEncoding: 'MP3' } | ||
} | ||
|
||
const spinner = report.activity() | ||
spinner.tick(`Fetching audio for ${animal}`) | ||
|
||
try { | ||
const [response] = await client.synthesizeSpeech(request) | ||
const writeFile = util.promisify(fs.writeFile) | ||
const fileNameMp3 = `${animal}.mp3` | ||
|
||
await writeFile(`${folder}/${fileNameMp3}`, response.audioContent, 'binary') | ||
await convertAudioToOgg(animal, folder) | ||
report.success(`mp3 and ogg files for ${animal}`) | ||
} catch (err) { | ||
report.error(err) | ||
} | ||
|
||
spinner.end() | ||
} | ||
|
||
report.info('Fetching audio files...') | ||
console.log('') | ||
const animals = require('../animals.json') | ||
|
||
animals.forEach(async animal => { | ||
const animalName = animal.name.toLowerCase() | ||
await generateAudioFile(animalName) | ||
const txt2audio = Txt2Audio({ | ||
text: animalName, | ||
filename: animalName, | ||
path: path.resolve(__dirname, '..', '..', 'audio', 'names'), | ||
gender: 'female', | ||
ogg: true, | ||
debug: true | ||
}) | ||
|
||
await txt2audio.generateAudio() | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.credits { | ||
position: absolute; | ||
bottom: 0; | ||
display: inline-block; | ||
color: #fafafa; | ||
background: #222; | ||
} |
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