Skip to content

Commit

Permalink
Ui improvements and add txt2audio lib to generate animals names
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavocardoso committed Mar 29, 2020
1 parent 8980957 commit cd5a091
Show file tree
Hide file tree
Showing 56 changed files with 154 additions and 315 deletions.
388 changes: 125 additions & 263 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"yurnalist": "^2.0.0"
},
"dependencies": {
"serviceworker-webpack-plugin": "^1.0.1"
"serviceworker-webpack-plugin": "^1.0.1",
"txt2audio": "^1.2.0"
}
}
Binary file modified src/audio/names/bear.mp3
Binary file not shown.
Binary file modified src/audio/names/bear.ogg
Binary file not shown.
Binary file modified src/audio/names/bird.mp3
Binary file not shown.
Binary file modified src/audio/names/bird.ogg
Binary file not shown.
Binary file modified src/audio/names/camel.mp3
Binary file not shown.
Binary file modified src/audio/names/camel.ogg
Binary file not shown.
Binary file modified src/audio/names/cat.mp3
Binary file not shown.
Binary file modified src/audio/names/cat.ogg
Binary file not shown.
Binary file modified src/audio/names/chicken.mp3
Binary file not shown.
Binary file modified src/audio/names/chicken.ogg
Binary file not shown.
Binary file modified src/audio/names/cow.mp3
Binary file not shown.
Binary file modified src/audio/names/cow.ogg
Binary file not shown.
Binary file modified src/audio/names/dog.mp3
Binary file not shown.
Binary file modified src/audio/names/dog.ogg
Binary file not shown.
Binary file modified src/audio/names/dolphin.mp3
Binary file not shown.
Binary file modified src/audio/names/dolphin.ogg
Binary file not shown.
Binary file modified src/audio/names/dove.mp3
Binary file not shown.
Binary file modified src/audio/names/dove.ogg
Binary file not shown.
Binary file modified src/audio/names/duck.mp3
Binary file not shown.
Binary file modified src/audio/names/duck.ogg
Binary file not shown.
Binary file modified src/audio/names/elephant.mp3
Binary file not shown.
Binary file modified src/audio/names/elephant.ogg
Binary file not shown.
Binary file modified src/audio/names/frog.mp3
Binary file not shown.
Binary file modified src/audio/names/frog.ogg
Binary file not shown.
Binary file modified src/audio/names/goat.mp3
Binary file not shown.
Binary file modified src/audio/names/goat.ogg
Binary file not shown.
Binary file modified src/audio/names/goose.mp3
Binary file not shown.
Binary file modified src/audio/names/goose.ogg
Binary file not shown.
Binary file modified src/audio/names/hamster.mp3
Binary file not shown.
Binary file modified src/audio/names/hamster.ogg
Binary file not shown.
Binary file modified src/audio/names/horse.mp3
Binary file not shown.
Binary file modified src/audio/names/horse.ogg
Binary file not shown.
Binary file modified src/audio/names/lion.mp3
Binary file not shown.
Binary file modified src/audio/names/lion.ogg
Binary file not shown.
Binary file modified src/audio/names/macaw.mp3
Binary file not shown.
Binary file modified src/audio/names/macaw.ogg
Binary file not shown.
Binary file modified src/audio/names/monkey.mp3
Binary file not shown.
Binary file modified src/audio/names/monkey.ogg
Binary file not shown.
Binary file modified src/audio/names/mouse.mp3
Binary file not shown.
Binary file modified src/audio/names/mouse.ogg
Binary file not shown.
Binary file modified src/audio/names/owl.mp3
Binary file not shown.
Binary file modified src/audio/names/owl.ogg
Binary file not shown.
Binary file modified src/audio/names/pig.mp3
Binary file not shown.
Binary file modified src/audio/names/pig.ogg
Binary file not shown.
Binary file modified src/audio/names/rooster.mp3
Binary file not shown.
Binary file modified src/audio/names/rooster.ogg
Binary file not shown.
Binary file modified src/audio/names/sheep.mp3
Binary file not shown.
Binary file modified src/audio/names/sheep.ogg
Binary file not shown.
Binary file modified src/audio/names/snake.mp3
Binary file not shown.
Binary file modified src/audio/names/snake.ogg
Binary file not shown.
6 changes: 6 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ <h2 class="name">Welcome</h2>
</div>
</section>
</div>

<section class="credits-button">
<h3 class="cta">Credits</h3>
</section>

<section class="credits"></section>
</section>
</body>
</html>
62 changes: 12 additions & 50 deletions src/js/tasks/generate-names-audio-files.js
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()
})
7 changes: 7 additions & 0 deletions src/sass/_credits.scss
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;
}
3 changes: 2 additions & 1 deletion src/sass/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

@import './intro';
@import './animals';
@import './credits';

*,
*:before,
Expand All @@ -34,7 +35,7 @@ html {
body {
height: 100%;
font: normal normal normal 16px/1.4 $font-family-base;
background-image: $body-default-background-color;
background-color: $body-default-background-color;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;

Expand Down

0 comments on commit cd5a091

Please sign in to comment.