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

Added .setVoice() to override default #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
37 changes: 34 additions & 3 deletions build/artyom.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
/// <reference path="artyom.d.ts" />
// Remove "export default " keywords if willing to build with `npm run artyom-build-window`
var Artyom = (function () {
var Artyom = /** @class */ (function () {
// Triggered at the declaration of
function Artyom() {
this.ArtyomCommands = [];
Expand All @@ -25,7 +25,7 @@ var Artyom = (function () {
// Italian
"it-IT": ["Google italiano", "it-IT", "it_IT"],
// Japanese
"jp-JP": ["Google 日本人", "ja-JP", "ja_JP"],
"ja-JP": ["Google 日本人", "ja-JP", "ja_JP"],
// English USA
"en-US": ["Google US English", "en-US", "en_US"],
// English UK
Expand Down Expand Up @@ -89,7 +89,8 @@ var Artyom = (function () {
speaking: false,
obeying: true,
soundex: false,
name: null
name: null,
voice: null,
};
this.ArtyomGarbageCollection = [];
this.ArtyomFlags = {
Expand Down Expand Up @@ -901,6 +902,9 @@ var Artyom = (function () {
_this.hey(resolve, reject);
});
}
if (config.hasOwnProperty("voice")) {
_this.setVoice(config.voice);
}
return Promise.resolve(true);
};
/**
Expand Down Expand Up @@ -1061,6 +1065,23 @@ var Artyom = (function () {
Artyom.prototype.getGarbageCollection = function () {
return this.ArtyomGarbageCollection;
};
/**
* Set a voice of the browser by it's voice name
* You can find a list of available voices using .getVoices()
*
* @param voiceName
*/
Artyom.prototype.setVoice = function (voiceName) {
this.debug('Setting voice to ' + voiceName);
var availableVoices = this.getVoices();
var newVoice = availableVoices.filter(function (v) { return v.name === voiceName; })[0];
if (!newVoice) {
console.warn("The provided voice " + voiceName + " isn't available, ignoring setVoice command");
return;
}
this.ArtyomProperties.voice = voiceName;
this.ArtyomVoice = newVoice;
};
/**
* Retrieve a single voice of the browser by it's language code.
* It will return the first voice available for the language on every device.
Expand Down Expand Up @@ -1357,6 +1378,7 @@ var Artyom = (function () {
* @returns {undefined}
*/
Artyom.prototype.talk = function (text, actualChunk, totalChunks, callbacks) {
var _this_1 = this;
var _this = this;
var msg = new SpeechSynthesisUtterance();
msg.text = text;
Expand All @@ -1370,6 +1392,15 @@ var Artyom = (function () {
availableVoice = _this.getVoice(callbacks.lang);
}
}
if (this.ArtyomProperties.voice) {
var availableVoices = this.getVoices();
var newVoice = availableVoices.filter(function (v) { return v.name === _this_1.ArtyomProperties.voice; })[0];
if (!newVoice) {
console.warn("The provided voice " + this.ArtyomProperties.voice + " isn't available, using default for " + _this.ArtyomProperties.lang);
return;
}
availableVoice = newVoice;
}
// If is a mobile device, provide only the language code in the lang property i.e "es_ES"
if (this.Device.isMobile) {
// Try to set the voice only if exists, otherwise don't use anything to use the native voice
Expand Down
37 changes: 34 additions & 3 deletions build/artyom.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
/// <reference path="artyom.d.ts" />
// Remove "export default " keywords if willing to build with `npm run artyom-build-window`
var Artyom = (function () {
var Artyom = /** @class */ (function () {
// Triggered at the declaration of
function Artyom() {
this.ArtyomCommands = [];
Expand All @@ -23,7 +23,7 @@ var Artyom = (function () {
// Italian
"it-IT": ["Google italiano", "it-IT", "it_IT"],
// Japanese
"jp-JP": ["Google 日本人", "ja-JP", "ja_JP"],
"ja-JP": ["Google 日本人", "ja-JP", "ja_JP"],
// English USA
"en-US": ["Google US English", "en-US", "en_US"],
// English UK
Expand Down Expand Up @@ -87,7 +87,8 @@ var Artyom = (function () {
speaking: false,
obeying: true,
soundex: false,
name: null
name: null,
voice: null,
};
this.ArtyomGarbageCollection = [];
this.ArtyomFlags = {
Expand Down Expand Up @@ -899,6 +900,9 @@ var Artyom = (function () {
_this.hey(resolve, reject);
});
}
if (config.hasOwnProperty("voice")) {
_this.setVoice(config.voice);
}
return Promise.resolve(true);
};
/**
Expand Down Expand Up @@ -1059,6 +1063,23 @@ var Artyom = (function () {
Artyom.prototype.getGarbageCollection = function () {
return this.ArtyomGarbageCollection;
};
/**
* Set a voice of the browser by it's voice name
* You can find a list of available voices using .getVoices()
*
* @param voiceName
*/
Artyom.prototype.setVoice = function (voiceName) {
this.debug('Setting voice to ' + voiceName);
var availableVoices = this.getVoices();
var newVoice = availableVoices.filter(function (v) { return v.name === voiceName; })[0];
if (!newVoice) {
console.warn("The provided voice " + voiceName + " isn't available, ignoring setVoice command");
return;
}
this.ArtyomProperties.voice = voiceName;
this.ArtyomVoice = newVoice;
};
/**
* Retrieve a single voice of the browser by it's language code.
* It will return the first voice available for the language on every device.
Expand Down Expand Up @@ -1355,6 +1376,7 @@ var Artyom = (function () {
* @returns {undefined}
*/
Artyom.prototype.talk = function (text, actualChunk, totalChunks, callbacks) {
var _this_1 = this;
var _this = this;
var msg = new SpeechSynthesisUtterance();
msg.text = text;
Expand All @@ -1368,6 +1390,15 @@ var Artyom = (function () {
availableVoice = _this.getVoice(callbacks.lang);
}
}
if (this.ArtyomProperties.voice) {
var availableVoices = this.getVoices();
var newVoice = availableVoices.filter(function (v) { return v.name === _this_1.ArtyomProperties.voice; })[0];
if (!newVoice) {
console.warn("The provided voice " + this.ArtyomProperties.voice + " isn't available, using default for " + _this.ArtyomProperties.lang);
return;
}
availableVoice = newVoice;
}
// If is a mobile device, provide only the language code in the lang property i.e "es_ES"
if (this.Device.isMobile) {
// Try to set the voice only if exists, otherwise don't use anything to use the native voice
Expand Down
1 change: 1 addition & 0 deletions source/artyom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface ArtyomProperties {
obeying?: boolean;
soundex?: boolean;
name?: string;
voice?: string;
}

interface PromptOptions {
Expand Down
39 changes: 37 additions & 2 deletions source/artyom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ export default class Artyom {
speaking: false,
obeying: true,
soundex: false,
name: null
name: null,
voice: null,
};

this.ArtyomGarbageCollection = [];
Expand Down Expand Up @@ -1095,6 +1096,10 @@ export default class Artyom {
});
}

if (config.hasOwnProperty("voice")) {
_this.setVoice(config.voice)
}

return Promise.resolve(true);
}

Expand Down Expand Up @@ -1275,6 +1280,26 @@ export default class Artyom {
return this.ArtyomGarbageCollection;
}



/**
* Set a voice of the browser by it's voice name
* You can find a list of available voices using .getVoices()
*
* @param voiceName
*/
setVoice(voiceName: string) {
this.debug('Setting voice to ' + voiceName)
const availableVoices = this.getVoices()
const newVoice = availableVoices.filter(v => v.name === voiceName)[0]
if (!newVoice) {
console.warn(`The provided voice ${voiceName} isn't available, ignoring setVoice command` );
return
}
this.ArtyomProperties.voice = voiceName
this.ArtyomVoice = newVoice;
}

/**
* Retrieve a single voice of the browser by it's language code.
* It will return the first voice available for the language on every device.
Expand Down Expand Up @@ -1620,7 +1645,7 @@ export default class Artyom {
msg.text = text;
msg.volume = this.ArtyomProperties.volume;
msg.rate = this.ArtyomProperties.speed;

// Select the voice according to the selected
let availableVoice = _this.getVoice(_this.ArtyomProperties.lang);

Expand All @@ -1630,6 +1655,16 @@ export default class Artyom {
availableVoice = _this.getVoice(callbacks.lang);
}
}

if (this.ArtyomProperties.voice) {
const availableVoices = this.getVoices()
const newVoice = availableVoices.filter(v => v.name === this.ArtyomProperties.voice)[0]
if (!newVoice) {
console.warn(`The provided voice ${this.ArtyomProperties.voice} isn't available, using default for ${_this.ArtyomProperties.lang}` );
return
}
availableVoice = newVoice
}

// If is a mobile device, provide only the language code in the lang property i.e "es_ES"
if(this.Device.isMobile){
Expand Down