Skip to content

Commit

Permalink
Merge pull request #135 from hosseinamin/master
Browse files Browse the repository at this point in the history
fix #134 & #100, override output to (headphone,builtinspeaker or default), +enhancement
  • Loading branch information
willwade authored Feb 7, 2019
2 parents 0706b23 + 0c5b69a commit 8caa77d
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 57 deletions.
2 changes: 1 addition & 1 deletion cordova/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<author email="hossein@aminbros.com" href="https://github.com/hosseinamin/">
Hossein Amin
</author>
<preference name="KeepAVAudioSessionAlwaysActive" value="true" />
<preference name="CordovaMediaIgnoreAVAudioSession" value="true" />
<preference name="KeyboardDisplayRequiresUserAction" value="false" />
<preference name="DisallowOverscroll" value="true" />
<preference name="MediaPlaybackRequiresUserAction" value="false" />
Expand Down
42 changes: 33 additions & 9 deletions html/edit-config.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ <h3 x-l10n>Helpers</h3>
<div class="col-sm-6">
<label class="m-t-10 m-b-10 checkbox-inline"><input type="checkbox" name="back_at_end"><span x-l10n>Back option for all branches</span></label>
</div>
<div class="col-sm-6 hide-for-non-cordova-ios">
<button id="ios-open-route-view" type="button" class="btn btn-primary">Open output audio manager</button>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -166,8 +169,15 @@ <h4><span x-l10n>First Time Run (Cue Voice)</span> <span id="auditory-cue-first-
<input class="form-control btn-lg" type="range" step="0.01" min="0.01" max="4" data-default="1" id="auditory_cue_first_run_voice_options.rateMul" name="auditory_cue_first_run_voice_options.rateMul" data-validator="number" data-disp="#disp-auditory_cue_first_run_voice_options__rateMul">
</div>
</div>
<div class="col-sm-6 visible-for-cordova">
<label class="checkbox-inline"><input type="checkbox" name="auditory_cue_first_run_voice_options.override_to_speaker"><span x-l10n>Override to speaker</span></label>
<div class="col-sm-12 hide-for-non-cordova-ios">
<div class="form-group">
<label>Override output</label>
<div class="radio-group">
<label class="radio-inline"><input type="radio" name="auditory_cue_first_run_voice_options.override_output" value=""><span x-l10n>None</span></label>
<label class="radio-inline"><input type="radio" name="auditory_cue_first_run_voice_options.override_output" value="builtinspeaker"><span x-l10n>Builtin Speaker</span></label>
<label class="radio-inline"><input type="radio" name="auditory_cue_first_run_voice_options.override_output" value="headphone"><span x-l10n>Headphone</span></label>
</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -210,7 +220,7 @@ <h4><span x-l10n>First Time Run (Cue Voice)</span> <span id="auditory-cue-first-
</div>
</div>
<div class="col-sm-4">
<div class="form-group hide-for-cordova">
<div class="form-group hide-for-cordova-ios">
<label for="ignore_key_release_time" x-l10n>Ignore key presses under n ms</label>
<input class="form-control" type="number" id="ignore_key_release_time" name="ignore_key_release_time" value="0" data-validator="number" data-dependent="#ignore_key_release_time_range">
<input type="range" id="ignore_key_release_time_range" class="form-control btn-lg" step="100" min="0" max="2000" data-dependent="#ignore_key_release_time">
Expand Down Expand Up @@ -255,8 +265,15 @@ <h4><span x-l10n>Cue Voice</span> <span id="auditory-cue-playback-wrp" class="vo
<input class="form-control btn-lg" type="range" step="0.01" min="0.01" max="4" data-default="1" id="auditory_cue_voice_options.rateMul" name="auditory_cue_voice_options.rateMul" data-validator="number" data-disp="#disp-auditory_cue_voice_options__rateMul">
</div>
</div>
<div class="col-sm-6 visible-for-cordova">
<label class="checkbox-inline"><input type="checkbox" name="auditory_cue_voice_options.override_to_speaker"><span x-l10n>Override to speaker</span></label>
<div class="col-sm-12 hide-for-non-cordova-ios">
<div class="form-group">
<label>Override output</label>
<div class="radio-group">
<label class="radio-inline"><input type="radio" name="auditory_cue_voice_options.override_output" value=""><span x-l10n>None</span></label>
<label class="radio-inline"><input type="radio" name="auditory_cue_voice_options.override_output" value="builtinspeaker"><span x-l10n>Builtin Speaker</span></label>
<label class="radio-inline"><input type="radio" name="auditory_cue_voice_options.override_output" value="headphone"><span x-l10n>Headphone</span></label>
</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -291,8 +308,15 @@ <h4><span x-l10n>Main Voice</span> <span id="auditory-main-playback-wrp" class="
<input class="form-control btn-lg" type="range" step="0.01" min="0.01" max="4" data-default="1" id="auditory_main_voice_options.rateMul" name="auditory_main_voice_options.rateMul" data-validator="number" data-disp="#disp-auditory_main_voice_options__rateMul">
</div>
</div>
<div class="col-sm-6 visible-for-cordova">
<label class="checkbox-inline"><input type="checkbox" name="auditory_main_voice_options.override_to_speaker"><span x-l10n>Override to speaker</span></label>
<div class="col-sm-12 hide-for-non-cordova-ios">
<div class="form-group">
<label>Override output</label>
<div class="radio-group">
<label class="radio-inline"><input type="radio" name="auditory_main_voice_options.override_output" value=""><span x-l10n>None</span></label>
<label class="radio-inline"><input type="radio" name="auditory_main_voice_options.override_output" value="builtinspeaker"><span x-l10n>Builtin Speaker</span></label>
<label class="radio-inline"><input type="radio" name="auditory_main_voice_options.override_output" value="headphone"><span x-l10n>Headphone</span></label>
</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -437,14 +461,14 @@ <h4 class="modal-title" x-l10n>Save</h4>
<div class="modal-body">
<div class="row">
<div class="col-xs-12">
<p class="visible-for-cordova" x-l10n>You can share or save the zip file.<p>
<p class="hide-for-non-cordova" x-l10n>You can share or save the zip file.<p>
<p class="hide-for-cordova" x-l10n>Please click on download.<p>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<a id="save-file--open-btn" href class="hide-for-cordova btn btn-success btn-lg">Download</a>
<a id="save-file--share-btn" href class="visible-for-cordova btn btn-primary btn-lg">Share</a>
<a id="save-file--share-btn" href class="hide-for-non-cordova btn btn-primary btn-lg">Share</a>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion html/js/NativeAccessApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
'is_software_keyboard_visible',
'request_audio_record_permission',
'add_key_command', 'remove_key_command',
'override_output_to_speaker',
'override_output', 'ios_open_manage_output_audio_view'
];

for(var i = 0, len = direct_delegates.length; i < len; ++i)
Expand Down
68 changes: 38 additions & 30 deletions html/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -984,16 +984,15 @@ proto.start_speaking = function(speech, opts) {
for(var key in opts)
if(key.indexOf('alt_') == 0)
delete opts[key];
var override_to_speaker = false,
var override_output = null,
promise = Promise.resolve();
if(typeof opts.override_to_speaker != 'undefined') {
override_to_speaker = opts.override_to_speaker
delete opts.override_to_speaker;
if(typeof opts.override_output != 'undefined') {
override_output = opts.override_output
delete opts.override_output;
}
if ((override_to_speaker && !self._last_override_to_speaker) ||
(!override_to_speaker && self._last_override_to_speaker)) {
self._last_override_to_speaker = override_to_speaker;
promise = self.api.override_output_to_speaker(override_to_speaker);
if (typeof self._last_override_output == 'undefined' || self._last_override_output != override_output) {
self._last_override_output = override_output;
promise = self.api.override_output(override_output);
}
return promise
.then(function () {
Expand All @@ -1018,7 +1017,7 @@ proto.start_speaking = function(speech, opts) {
delete opts.rateMul
var voiceId = opts.voiceId;
delete opts.voiceId;
delete opts.override_to_speaker;
delete opts.override_output;
// TODO:: control audio playback,
// delay can be implemented if access to audio playback is at this level
var retobj = {};
Expand Down Expand Up @@ -1121,26 +1120,35 @@ proto._cordova_stop_audio = function() {

proto._cordova_play_audio = function(src, opts) {
var self = this;
return new Promise(function(resolve, reject) {
self._cordova_stop_audio()
src = _cordova_fix_url(src)
var media = self._cordova_media =
new Media(src,
function() {
resolve()
},
function(err) {
reject("Error loading media: " + src +
", error: " + err.code);
});
if(opts.volume)
media.setVolume(opts.volume)
var play_opts = {};
if(opts.override_to_speaker)
play_opts.overrideToSpeaker = true;
self._last_override_to_speaker = !!play_opts.overrideToSpeaker;
media.play(play_opts);
});
self._cordova_stop_audio()
var override_output = null,
promise = Promise.resolve();
if(typeof opts.override_output != 'undefined') {
override_output = opts.override_output
delete opts.override_output;
}
if (typeof self._last_override_output == 'undefined' || self._last_override_output != override_output) {
self._last_override_output = override_output;
promise = self.api.override_output(override_output);
}
return promise
.then(function () {
return new Promise(function(resolve, reject) {
src = _cordova_fix_url(src)
var media = self._cordova_media =
new Media(src,
function() {
resolve()
},
function(err) {
reject("Error loading media: " + src +
", error: " + err.code);
});
if(opts.volume)
media.setVolume(opts.volume)
media.play();
})
});
}

proto.stop_audio = function() {
Expand All @@ -1163,7 +1171,7 @@ proto.stop_audio = function() {


proto.play_audio = function(src, opts) {
opts = opts || {};
opts = Object.assign({}, opts)
if(window.cordova && window.Media) {
// alternative approach
return this._cordova_play_audio(src, opts)
Expand Down
8 changes: 7 additions & 1 deletion html/js/edit-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ function _fix_config(cfg) {
}

function bind_dom_event_handlers () {
$('#ios-open-route-view').click(function ($evt) {
$evt.preventDefault();
if (speaku.is_native) {
speaku.api.ios_open_manage_output_audio_view()
}
});
$('.vbl-btn').on('click', vbl_btn_onclick);
function vbl_btn_onclick ($evt) {
var vbl_link_id = $($evt.target).data('vbl');
Expand Down Expand Up @@ -1366,7 +1372,7 @@ function _vbl_voice_tmpl_options (locale) {
});
if (vlist.length == 0) {
vlist = _.filter(all_voices, function (v) {
return v.locale.split('-')[0] == locale.split('-')[0];
return (v.locale+"").split('-')[0] == locale.split('-')[0];
});
}
return _.map(vlist, function (v) {
Expand Down
6 changes: 0 additions & 6 deletions html/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1594,12 +1594,6 @@ function eval_config(config) {
}
if(!('can_edit' in config))
config.can_edit = true;
config._has_override_to_speaker = _.filter([
'auditory_main_voice_options', 'auditory_cue_voice_options',
'auditory_cue_first_run_voice_options'
], function(name) {
return config[name] && !!config[name].override_to_speaker;
}).length > 0;
return config;
}

Expand Down
21 changes: 17 additions & 4 deletions html/quick-setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,15 @@ <h4><span x-l10n>Cue Voice</span> <span id="auditory-cue-playback-wrp" class="vo
<input class="form-control btn-lg" type="range" step="0.01" min="0.01" max="4" data-default="1" id="auditory_cue_voice_options.rateMul" name="auditory_cue_voice_options.rateMul" data-validator="number" data-disp="#disp-auditory_cue_voice_options__rateMul">
</div>
</div>
<div class="col-sm-6 visible-for-cordova">
<label class="checkbox-inline"><input type="checkbox" name="auditory_cue_voice_options.override_to_speaker" checked="True"><span x-l10n>Override to speaker</span></label>
<div class="col-sm-12 hide-for-non-cordova-ios">
<div class="form-group">
<label>Override output</label>
<div class="radio-group">
<label class="radio-inline"><input type="radio" name="auditory_cue_voice_options.override_output" value=""><span x-l10n>None</span></label>
<label class="radio-inline"><input type="radio" name="auditory_cue_voice_options.override_output" value="builtinspeaker"><span x-l10n>Builtin Speaker</span></label>
<label class="radio-inline"><input type="radio" name="auditory_cue_voice_options.override_output" value="headphone"><span x-l10n>Headphone</span></label>
</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -128,8 +135,14 @@ <h4><span x-l10n>Main Voice</span> <span id="auditory-main-playback-wrp" class="
<input class="form-control btn-lg" type="range" step="0.01" min="0.01" max="4" data-default="1" id="auditory_main_voice_options.rateMul" name="auditory_main_voice_options.rateMul" data-validator="number" data-disp="#disp-auditory_main_voice_options__rateMul">
</div>
</div>
<div class="col-sm-6 visible-for-cordova">
<label class="checkbox-inline"><input type="checkbox" name="auditory_main_voice_options.override_to_speaker" checked="True"><span x-l10n>Override to speaker</span></label>
<div class="col-sm-12 hide-for-non-cordova-ios">
<div class="form-group">
<label>Override output</label>
<div class="radio-group">
<label class="radio-inline"><input type="radio" name="auditory_main_voice_options.override_output" value=""><span x-l10n>None</span></label>
<label class="radio-inline"><input type="radio" name="auditory_main_voice_options.override_output" value="builtinspeaker"><span x-l10n>Builtin Speaker</span></label>
<label class="radio-inline"><input type="radio" name="auditory_main_voice_options.override_output" value="headphone"><span x-l10n>Headphone</span></label>
</div>
</div>
</div>
</div>
Expand Down
23 changes: 18 additions & 5 deletions html/scss/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -129,30 +129,43 @@ html.ios {
margin-top: 100px;
}
}
.visible-for-ios {
.hide-for-non-ios {
display: block;
}
.hide-for-ios {
display: none;
}
}
html.cordova {
.visible-for-cordova {
.hide-for-non-cordova {
display: block;
}
.hide-for-cordova {
display: none;
}
}

html.cordova.ios {
.hide-for-non-cordova-ios {
display: block;
}
.hide-for-cordova-ios {
display: none;
}
}
html {
.visible-for-ios {
.hide-for-non-cordova-ios {
display: none;
}
.hide-for-cordova-ios {
display: block;
}
.hide-for-non-ios {
display: none;
}
.hide-for-ios {
display: block;
}
.visible-for-cordova {
.hide-for-non-cordova {
display: none;
}
.hide-for-cordova {
Expand Down

0 comments on commit 8caa77d

Please sign in to comment.