#144 [es] allow multiple pronunciations
This commit is contained in:
parent
57199402cb
commit
df74c06750
|
@ -7,11 +7,14 @@
|
||||||
<small v-if="link">
|
<small v-if="link">
|
||||||
(<nuxt-link :to="'/' + pronoun.canonicalName">{{ pronoun.canonicalName }}</nuxt-link>)
|
(<nuxt-link :to="'/' + pronoun.canonicalName">{{ pronoun.canonicalName }}</nuxt-link>)
|
||||||
</small>
|
</small>
|
||||||
<a v-if="config.pronunciation.enabled && pronounce && pronoun.pronounceable && example.pronounce(pronoun)"
|
<template v-if="config.pronunciation.enabled && pronounce && pronoun.pronounceable && example.pronounce(pronoun)">
|
||||||
:href="pronunciationLink"
|
<a v-for="(link, name) in pronunciationLinks"
|
||||||
@click.prevent="pronounce">
|
class="mr-2"
|
||||||
<Icon v="volume"/>
|
:href="link"
|
||||||
</a>
|
@click.prevent="pronounce(link)">
|
||||||
|
<Icon v="volume"/><sub v-if="name">{{name}}</sub>
|
||||||
|
</a>
|
||||||
|
</template>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -27,8 +30,8 @@
|
||||||
pronunciation: { type: Boolean },
|
pronunciation: { type: Boolean },
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
pronounce() {
|
pronounce(link) {
|
||||||
const sound = new Audio(this.pronunciationLink);
|
const sound = new Audio(link);
|
||||||
sound.play();
|
sound.play();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -52,8 +55,15 @@
|
||||||
pronounToString() {
|
pronounToString() {
|
||||||
return this.pronounBase && pronouns[this.pronounBase].equals(this.pronoun) ? this.pronounBase : this.pronoun.toString();
|
return this.pronounBase && pronouns[this.pronounBase].equals(this.pronoun) ? this.pronounBase : this.pronoun.toString();
|
||||||
},
|
},
|
||||||
pronunciationLink() {
|
pronunciationLinks() {
|
||||||
return `/api/pronounce/${this.pronounToString}?example=${encodeURIComponent(this.example.toString())}`;
|
const justOne = Object.keys(this.config.pronunciation.voices).length === 1;
|
||||||
|
|
||||||
|
const links = {};
|
||||||
|
for (let country in this.config.pronunciation.voices) {
|
||||||
|
if (!this.config.pronunciation.voices.hasOwnProperty(country)) { continue; }
|
||||||
|
links[justOne ? '' : country] = `/api/pronounce/${country}/${this.pronounToString}?example=${encodeURIComponent(this.example.toString())}`;
|
||||||
|
}
|
||||||
|
return links;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,11 @@ pronouns:
|
||||||
|
|
||||||
pronunciation:
|
pronunciation:
|
||||||
enabled: true
|
enabled: true
|
||||||
language: 'en-GB'
|
voices:
|
||||||
voice: 'Emma'
|
GB:
|
||||||
engine: 'neural'
|
language: 'en-GB'
|
||||||
|
voice: 'Emma'
|
||||||
|
engine: 'neural'
|
||||||
|
|
||||||
sources:
|
sources:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
|
@ -20,9 +20,15 @@ pronouns:
|
||||||
|
|
||||||
pronunciation:
|
pronunciation:
|
||||||
enabled: true
|
enabled: true
|
||||||
language: 'es-ES'
|
voices:
|
||||||
voice: 'Lucia'
|
ES:
|
||||||
engine: 'standard'
|
language: 'es-ES'
|
||||||
|
voice: 'Lucia'
|
||||||
|
engine: 'standard'
|
||||||
|
MX:
|
||||||
|
language: 'es-MX'
|
||||||
|
voice: 'Mia'
|
||||||
|
engine: 'standard'
|
||||||
|
|
||||||
sources:
|
sources:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
|
@ -44,9 +44,11 @@ pronouns:
|
||||||
|
|
||||||
pronunciation:
|
pronunciation:
|
||||||
enabled: true
|
enabled: true
|
||||||
language: 'pl-PL'
|
voices:
|
||||||
voice: 'Ewa'
|
PL:
|
||||||
engine: 'standard'
|
language: 'pl-PL'
|
||||||
|
voice: 'Ewa'
|
||||||
|
engine: 'standard'
|
||||||
|
|
||||||
sources:
|
sources:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
|
@ -10,7 +10,7 @@ import S3 from 'aws-sdk/clients/s3';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get('/pronounce/:pronoun*', async (req, res) => {
|
router.get('/pronounce/:voice/:pronoun*', async (req, res) => {
|
||||||
const pronounString = req.params.pronoun + req.params[0];
|
const pronounString = req.params.pronoun + req.params[0];
|
||||||
const pronoun = buildPronoun(
|
const pronoun = buildPronoun(
|
||||||
parsePronouns(loadTsv('pronouns/pronouns')),
|
parsePronouns(loadTsv('pronouns/pronouns')),
|
||||||
|
@ -34,10 +34,17 @@ router.get('/pronounce/:pronoun*', async (req, res) => {
|
||||||
return res.status(404).json({error: 'Not found'});
|
return res.status(404).json({error: 'Not found'});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const voice = req.config.pronunciation.voices[req.params.voice];
|
||||||
|
if (!voice) {
|
||||||
|
return res.status(404).json({error: 'Not found'});
|
||||||
|
}
|
||||||
|
|
||||||
const s3 = new S3(awsConfig);
|
const s3 = new S3(awsConfig);
|
||||||
const polly = new Polly(awsConfig);
|
const polly = new Polly(awsConfig);
|
||||||
|
|
||||||
const key = `pronunciation/${req.config.locale}/${pronounString}/${sha1(text)}.mp3`;
|
const key = `pronunciation/${req.config.locale}-${req.params.voice}/${pronounString}/${sha1(text)}.mp3`;
|
||||||
|
|
||||||
|
console.log(key, voice);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const s3getResponse = await s3.getObject({Key: key}).promise();
|
const s3getResponse = await s3.getObject({Key: key}).promise();
|
||||||
|
@ -47,9 +54,9 @@ router.get('/pronounce/:pronoun*', async (req, res) => {
|
||||||
TextType: 'ssml',
|
TextType: 'ssml',
|
||||||
Text: text,
|
Text: text,
|
||||||
OutputFormat: 'mp3',
|
OutputFormat: 'mp3',
|
||||||
LanguageCode: req.config.pronunciation.language,
|
LanguageCode: voice.language,
|
||||||
VoiceId: req.config.pronunciation.voice,
|
VoiceId: voice.voice,
|
||||||
Engine: req.config.pronunciation.engine,
|
Engine: voice.engine,
|
||||||
}).promise();
|
}).promise();
|
||||||
|
|
||||||
const s3putResponse = await s3.putObject({
|
const s3putResponse = await s3.putObject({
|
||||||
|
|
Reference in New Issue