Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct differentiation between local and cloud voices #1176

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/providers/SpeechProvider/SpeechProvider.actions.js
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ import {
filterLocalLangs
} from '../../i18n';
import tts from './tts';
import { isAndroid } from '../../cordova-util';
import { showNotification } from '../../components/Notifications/Notifications.actions';

export function requestVoices() {
@@ -185,19 +186,35 @@ export function getVoices() {
const regex = new RegExp('^[a-zA-Z]{2,}-$', 'g');
const fvoices = pvoices.filter(voice => !regex.test(voice.lang));
voices = fvoices.map(
({ voiceURI, lang, name, Locale, ShortName, DisplayName, Gender }) => {
({
voiceURI,
lang,
name,
Locale,
ShortName,
DisplayName,
Gender,
localService,
features
}) => {
let voice = {};
if (lang) {
voice.lang = lang;
} else if (Locale) {
voice.lang = Locale;
}
if (voiceURI) {
if (isAndroid() && features && /notInstalled/.test(features)) {
voice.voiceURI = voiceURI;
voice.voiceSource = 'cloud';
voice.isAzure = false;
} else if (voiceURI && localService) {
voice.voiceURI = voiceURI;
voice.voiceSource = 'local';
} else if (ShortName) {
voice.voiceURI = ShortName;
voice.isAzure = false;
} else if ((ShortName || voiceURI) && !localService) {
voice.voiceURI = ShortName || voiceURI;
voice.voiceSource = 'cloud';
ShortName ? (voice.isAzure = true) : (voice.isAzure = false);
}
if (name) {
voice.name = name;
17 changes: 9 additions & 8 deletions src/providers/SpeechProvider/tts.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import { getStore } from '../../store';
// this is the local synthesizer
let synth = window.speechSynthesis;

// this is the cloud synthesizer
// this is the azure synthesizer
var azureSynthesizer;

const audioElement = new Audio();
@@ -97,17 +97,17 @@ const tts = {
},

async getVoices() {
let cloudVoices = [];
// first, request for cloud based voices
let azureVoices = [];
// first, request for azure based voices
try {
cloudVoices = await API.getAzureVoices();
azureVoices = await API.getAzureVoices();
} catch (err) {
console.error(err.message);
}
return new Promise((resolve, reject) => {
platformVoices = this._getPlatformVoices() || [];
if (platformVoices.length) {
resolve(platformVoices.concat(cloudVoices));
resolve(platformVoices.concat(azureVoices));
}

// Android
@@ -120,13 +120,13 @@ const tts = {
synth.removeEventListener('voiceschanged', voiceslst);
// On Cordova, voice results are under `._list`
platformVoices = voices._list || voices;
resolve(platformVoices.concat(cloudVoices));
resolve(platformVoices.concat(azureVoices));
}
});
} else if (isCordova()) {
// Samsung devices on Cordova
platformVoices = this._getPlatformVoices();
resolve(platformVoices.concat(cloudVoices));
resolve(platformVoices.concat(azureVoices));
}
});
},
@@ -190,7 +190,8 @@ const tts = {
setCloudSpeakAlertTimeout
) {
const voice = this.getVoiceByVoiceURI(voiceURI);
if (voice && voice.voiceSource === 'cloud') {

if (voice && voice.voiceSource === 'cloud' && voice.isAzure) {
const speakAlertTimeoutId = setCloudSpeakAlertTimeout();
// set voice to speak
azureSynthesizer.properties.setProperty(