Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/babel/preset-env-7…
Browse files Browse the repository at this point in the history
….23.8
  • Loading branch information
jankapunkt authored Feb 17, 2024
2 parents 816befd + 5f7f976 commit 56babc1
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 35 deletions.
15 changes: 11 additions & 4 deletions dist/EasySpeech.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,10 @@ EasySpeech.speak = function (_ref4) {
utterance.volume = getValue({
volume: volume
});
debugUtterance(utterance);
var isMsNatural = utterance.voice && utterance.voice.name && utterance.voice.name.toLocaleLowerCase().includes('(natural)');
debugUtterance(utterance, {
isMsNatural: isMsNatural
});
utteranceEvents.forEach(function (name) {
var _internal$handlers;
var fn = handlers[name];
Expand Down Expand Up @@ -801,7 +804,8 @@ EasySpeech.speak = function (_ref4) {
utterance.addEventListener('start', function () {
patches.paused = false;
patches.speaking = true;
var useResumeInfinity = typeof infiniteResume === 'boolean' ? infiniteResume : !patches.isFirefox && !patches.isSafari && patches.isAndroid !== true;
var defaultResumeInfinity = !isMsNatural && !patches.isFirefox && !patches.isSafari && patches.isAndroid !== true;
var useResumeInfinity = typeof infiniteResume === 'boolean' ? infiniteResume : defaultResumeInfinity;
if (useResumeInfinity) {
resumeInfinity(utterance);
}
Expand All @@ -826,7 +830,7 @@ EasySpeech.speak = function (_ref4) {
clearTimeout(timeoutResumeInfinity);
internal.speechSynthesis.cancel();
setTimeout(function () {
internal.speechSynthesis.speak(utterance);
return internal.speechSynthesis.speak(utterance);
}, 10);
});
};
Expand All @@ -837,7 +841,10 @@ var debugUtterance = function debugUtterance(_ref5) {
pitch = _ref5.pitch,
rate = _ref5.rate,
volume = _ref5.volume;
debug("utterance: voice=".concat(voice === null || voice === void 0 ? void 0 : voice.name, " volume=").concat(volume, " rate=").concat(rate, " pitch=").concat(pitch));
var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref6$isMsNatural = _ref6.isMsNatural,
isMsNatural = _ref6$isMsNatural === void 0 ? false : _ref6$isMsNatural;
debug("utterance: voice=".concat(voice === null || voice === void 0 ? void 0 : voice.name, " volume=").concat(volume, " rate=").concat(rate, " pitch=").concat(pitch, " isMsNatural=").concat(isMsNatural));
};

/**
Expand Down
15 changes: 11 additions & 4 deletions dist/EasySpeech.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,10 @@ EasySpeech.speak = function (_ref4) {
utterance.volume = getValue({
volume: volume
});
debugUtterance(utterance);
var isMsNatural = utterance.voice && utterance.voice.name && utterance.voice.name.toLocaleLowerCase().includes('(natural)');
debugUtterance(utterance, {
isMsNatural: isMsNatural
});
utteranceEvents.forEach(function (name) {
var _internal$handlers;
var fn = handlers[name];
Expand Down Expand Up @@ -799,7 +802,8 @@ EasySpeech.speak = function (_ref4) {
utterance.addEventListener('start', function () {
patches.paused = false;
patches.speaking = true;
var useResumeInfinity = typeof infiniteResume === 'boolean' ? infiniteResume : !patches.isFirefox && !patches.isSafari && patches.isAndroid !== true;
var defaultResumeInfinity = !isMsNatural && !patches.isFirefox && !patches.isSafari && patches.isAndroid !== true;
var useResumeInfinity = typeof infiniteResume === 'boolean' ? infiniteResume : defaultResumeInfinity;
if (useResumeInfinity) {
resumeInfinity(utterance);
}
Expand All @@ -824,7 +828,7 @@ EasySpeech.speak = function (_ref4) {
clearTimeout(timeoutResumeInfinity);
internal.speechSynthesis.cancel();
setTimeout(function () {
internal.speechSynthesis.speak(utterance);
return internal.speechSynthesis.speak(utterance);
}, 10);
});
};
Expand All @@ -835,7 +839,10 @@ var debugUtterance = function debugUtterance(_ref5) {
pitch = _ref5.pitch,
rate = _ref5.rate,
volume = _ref5.volume;
debug("utterance: voice=".concat(voice === null || voice === void 0 ? void 0 : voice.name, " volume=").concat(volume, " rate=").concat(rate, " pitch=").concat(pitch));
var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref6$isMsNatural = _ref6.isMsNatural,
isMsNatural = _ref6$isMsNatural === void 0 ? false : _ref6$isMsNatural;
debug("utterance: voice=".concat(voice === null || voice === void 0 ? void 0 : voice.name, " volume=").concat(volume, " rate=").concat(rate, " pitch=").concat(pitch, " isMsNatural=").concat(isMsNatural));
};

/**
Expand Down
15 changes: 11 additions & 4 deletions dist/EasySpeech.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,10 @@ var EasySpeech = (function () {
utterance.volume = getValue({
volume: volume
});
debugUtterance(utterance);
var isMsNatural = utterance.voice && utterance.voice.name && utterance.voice.name.toLocaleLowerCase().includes('(natural)');
debugUtterance(utterance, {
isMsNatural: isMsNatural
});
utteranceEvents.forEach(function (name) {
var _internal$handlers;
var fn = handlers[name];
Expand Down Expand Up @@ -914,7 +917,8 @@ var EasySpeech = (function () {
utterance.addEventListener('start', function () {
patches.paused = false;
patches.speaking = true;
var useResumeInfinity = typeof infiniteResume === 'boolean' ? infiniteResume : !patches.isFirefox && !patches.isSafari && patches.isAndroid !== true;
var defaultResumeInfinity = !isMsNatural && !patches.isFirefox && !patches.isSafari && patches.isAndroid !== true;
var useResumeInfinity = typeof infiniteResume === 'boolean' ? infiniteResume : defaultResumeInfinity;
if (useResumeInfinity) {
resumeInfinity(utterance);
}
Expand All @@ -939,7 +943,7 @@ var EasySpeech = (function () {
clearTimeout(timeoutResumeInfinity);
internal.speechSynthesis.cancel();
setTimeout(function () {
internal.speechSynthesis.speak(utterance);
return internal.speechSynthesis.speak(utterance);
}, 10);
});
};
Expand All @@ -950,7 +954,10 @@ var EasySpeech = (function () {
pitch = _ref5.pitch,
rate = _ref5.rate,
volume = _ref5.volume;
debug("utterance: voice=".concat(voice === null || voice === void 0 ? void 0 : voice.name, " volume=").concat(volume, " rate=").concat(rate, " pitch=").concat(pitch));
var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref6$isMsNatural = _ref6.isMsNatural,
isMsNatural = _ref6$isMsNatural === void 0 ? false : _ref6$isMsNatural;
debug("utterance: voice=".concat(voice === null || voice === void 0 ? void 0 : voice.name, " volume=").concat(volume, " rate=").concat(rate, " pitch=").concat(pitch, " isMsNatural=").concat(isMsNatural));
};

/**
Expand Down
25 changes: 18 additions & 7 deletions dist/EasySpeech.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,14 @@ EasySpeech.speak = ({ text, voice, pitch, rate, volume, force, infiniteResume, .
utterance.pitch = getValue({ pitch });
utterance.rate = getValue({ rate });
utterance.volume = getValue({ volume });
debugUtterance(utterance);

const isMsNatural =
utterance.voice &&
utterance.voice.name &&
utterance.voice.name
.toLocaleLowerCase()
.includes('(natural)');
debugUtterance(utterance, { isMsNatural });

utteranceEvents.forEach(name => {
const fn = handlers[name];
Expand Down Expand Up @@ -769,9 +776,15 @@ EasySpeech.speak = ({ text, voice, pitch, rate, volume, force, infiniteResume, .
patches.paused = false;
patches.speaking = true;

const defaultResumeInfinity = (
!isMsNatural &&
!patches.isFirefox &&
!patches.isSafari &&
patches.isAndroid !== true
);
const useResumeInfinity = typeof infiniteResume === 'boolean'
? infiniteResume
: !patches.isFirefox && !patches.isSafari && patches.isAndroid !== true;
: defaultResumeInfinity;

if (useResumeInfinity) {
resumeInfinity(utterance);
Expand All @@ -798,15 +811,13 @@ EasySpeech.speak = ({ text, voice, pitch, rate, volume, force, infiniteResume, .
clearTimeout(timeoutResumeInfinity);
internal.speechSynthesis.cancel();

setTimeout(() => {
internal.speechSynthesis.speak(utterance);
}, 10);
setTimeout(() => internal.speechSynthesis.speak(utterance), 10);
})
};

/** @private **/
const debugUtterance = ({ voice, pitch, rate, volume }) => {
debug(`utterance: voice=${voice?.name} volume=${volume} rate=${rate} pitch=${pitch}`);
const debugUtterance = ({ voice, pitch, rate, volume }, { isMsNatural = false } = {}) => {
debug(`utterance: voice=${voice?.name} volume=${volume} rate=${rate} pitch=${pitch} isMsNatural=${isMsNatural}`);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion docs/demo.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ <h1 class="text-center text-white ">
</a>
</div>

<div class="containter text-center">
<a href="https://github.com/jankapunkt/easy-speech/blob/master/API.md" class="btn btn-primary text-decoration-none text-black ">API Doc</a>
<a href="https://github.com/jankapunkt/easy-speech" class="btn btn-success text-decoration-none text-black ">GitHub</a>

<div class="container text-center">
<a href="https://github.com/jankapunkt/easy-speech/blob/master/API.md">API Docs</a>
<span>|</span>
<a href="https://github.com/jankapunkt/easy-speech">GitHub</a>
</div>
</div>
<div class="container">
Expand Down Expand Up @@ -179,8 +179,8 @@ <h1 class="text-center text-white ">
</div>
</div>
<hr>
<div class="containter text-center">
<a href="https://github.com/jankapunkt/easy-speech/blob/master/API.md">API Doc</a>
<div class="container text-center">
<a href="https://github.com/jankapunkt/easy-speech/blob/master/API.md">API Docs</a>
<span>|</span>
<a href="https://github.com/jankapunkt/easy-speech">GitHub</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easy-speech",
"version": "2.3.0",
"version": "2.3.1",
"description": "Cross browser Speech Synthesis",
"type": "module",
"main": "./dist/EasySpeech.cjs.js",
Expand Down
25 changes: 18 additions & 7 deletions src/EasySpeech.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,14 @@ EasySpeech.speak = ({ text, voice, pitch, rate, volume, force, infiniteResume, .
utterance.pitch = getValue({ pitch })
utterance.rate = getValue({ rate })
utterance.volume = getValue({ volume })
debugUtterance(utterance)

const isMsNatural =
utterance.voice &&
utterance.voice.name &&
utterance.voice.name
.toLocaleLowerCase()
.includes('(natural)')
debugUtterance(utterance, { isMsNatural })

utteranceEvents.forEach(name => {
const fn = handlers[name]
Expand Down Expand Up @@ -769,9 +776,15 @@ EasySpeech.speak = ({ text, voice, pitch, rate, volume, force, infiniteResume, .
patches.paused = false
patches.speaking = true

const defaultResumeInfinity = (
!isMsNatural &&
!patches.isFirefox &&
!patches.isSafari &&
patches.isAndroid !== true
)
const useResumeInfinity = typeof infiniteResume === 'boolean'
? infiniteResume
: !patches.isFirefox && !patches.isSafari && patches.isAndroid !== true
: defaultResumeInfinity

if (useResumeInfinity) {
resumeInfinity(utterance)
Expand All @@ -798,15 +811,13 @@ EasySpeech.speak = ({ text, voice, pitch, rate, volume, force, infiniteResume, .
clearTimeout(timeoutResumeInfinity)
internal.speechSynthesis.cancel()

setTimeout(() => {
internal.speechSynthesis.speak(utterance)
}, 10)
setTimeout(() => internal.speechSynthesis.speak(utterance), 10)
})
}

/** @private **/
const debugUtterance = ({ voice, pitch, rate, volume }) => {
debug(`utterance: voice=${voice?.name} volume=${volume} rate=${rate} pitch=${pitch}`)
const debugUtterance = ({ voice, pitch, rate, volume }, { isMsNatural = false } = {}) => {
debug(`utterance: voice=${voice?.name} volume=${volume} rate=${rate} pitch=${pitch} isMsNatural=${isMsNatural}`)
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/unit.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ describe('unit tests', function () {
expect(defaultVoice).to.equal(voices[1])
})
it('sets a language-specific voice as default voice, if no .default is available', async () => {
global.navigator = { language: 'de-DE' }
const window = {}
window.window = window // this is intended!
global.window = global.window || window
window.navigator = { language: 'de-DE' }
const voices = [{}, {}, { lang: 'de_DE' }]
await initScope({
speechSynthesis: { getVoices: () => voices }
Expand Down

0 comments on commit 56babc1

Please sign in to comment.