Skip to content

Commit

Permalink
Add audio playback for feedback, hints, and solutions to learner view (
Browse files Browse the repository at this point in the history
…oppia#4346)

* Rename AudioTranslationManagerService to AudioTranslationLanguageService.

* Create AudioTranslationManagerService.

* Add audio playback for feedback in learner view. Still need to do hints and solutions.

* Add tests for AudioTranslationManager.

* Lint.

* Reset hints array. Fix typo.

* Play audio for hints and solutions.

* Lint.

* Play autogenerated feedback audio.

* Treat feedback audio translations as one-off.

* Fix test.

* Lint.

* Typo.

* Typo.

* Add comments.

* Lint.
  • Loading branch information
tjiang11 authored and seanlip committed Jan 6, 2018
1 parent 34fbc9c commit 6adb3f9
Show file tree
Hide file tree
Showing 28 changed files with 742 additions and 312 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ oppia.directive('hintAndSolutionButtons', [
HintsAndSolutionManagerService.isSolutionConsumed);

var resetLocalHintsArray = function() {
$scope.hintIndexes = [];
var numHints = HintsAndSolutionManagerService.getNumHints();
for (var index = 0; index < numHints; index++) {
$scope.hintIndexes.push(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,6 @@ oppia.factory('ExplorationObjectFactory', [
return this.states.getAllAudioTranslations(languageCode);
};

Exploration.prototype.getAllAudioTranslationsFileSizeMB =
function(languageCode) {
var totalFileSizeMB = 0;
var allAudioTranslations =
this.states.getAllAudioTranslations(languageCode);
for (var audioTranslationStateName in allAudioTranslations) {
totalFileSizeMB +=
allAudioTranslations[audioTranslationStateName].getFileSizeMB();
}
return totalFileSizeMB;
};

Exploration.prototype.getLanguageCode = function() {
return this.languageCode;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,25 @@ describe('Exploration object factory', function() {
it('should correctly get audio translations from an exploration',
function() {
expect(exploration.getAllAudioTranslations('hi-en')).toEqual({
'first state': atof.createFromBackendDict({
'first state': [atof.createFromBackendDict({
filename: 'myfile3.mp3',
file_size_bytes: 430000,
needs_update: false
}),
'second state': atof.createFromBackendDict({
})],
'second state': [atof.createFromBackendDict({
filename: 'myfile2.mp3',
file_size_bytes: 120000,
needs_update: false
})
})]
});
expect(exploration.getAllAudioTranslations('en')).toEqual({
'first state': atof.createFromBackendDict({
'first state': [atof.createFromBackendDict({
filename: 'myfile1.mp3',
file_size_bytes: 210000,
needs_update: false
})
})],
'second state': []
});
});

it('should get the correct file size in MB of all audio translations',
function() {
var NUM_BYTES_IN_MB = 1 << 20;
expect(exploration.getAllAudioTranslationsFileSizeMB('hi-en')).toEqual(
550000 / NUM_BYTES_IN_MB);
expect(exploration.getAllAudioTranslationsFileSizeMB('en')).toEqual(
210000 / NUM_BYTES_IN_MB);
});
});
});
101 changes: 93 additions & 8 deletions core/templates/dev/head/domain/exploration/StatesObjectFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,110 @@ oppia.factory('StatesObjectFactory', [
States.prototype.getAllAudioLanguageCodes = function() {
var allAudioLanguageCodes = [];
for (var stateName in this._states) {
var audioTranslationsForState =
this._states[stateName].content.getBindableAudioTranslations();
for (var languageCode in audioTranslationsForState) {
var state = this._states[stateName];

var audioTranslationsForStateContent =
state.content.getBindableAudioTranslations();
for (var languageCode in audioTranslationsForStateContent) {
if (allAudioLanguageCodes.indexOf(languageCode) === -1) {
allAudioLanguageCodes.push(languageCode);
}
}

state.interaction.answerGroups.forEach(function(answerGroup) {
var audioTranslationsForAnswerGroup =
answerGroup.outcome.feedback.getBindableAudioTranslations();
for (var languageCode in audioTranslationsForAnswerGroup) {
if (allAudioLanguageCodes.indexOf(languageCode) === -1) {
allAudioLanguageCodes.push(languageCode);
}
}
});

if (state.interaction.defaultOutcome != null) {
var audioTranslationsForDefaultOutcome =
state.interaction.defaultOutcome.feedback
.getBindableAudioTranslations();
for (var languageCode in audioTranslationsForDefaultOutcome) {
if (allAudioLanguageCodes.indexOf(languageCode) === -1) {
allAudioLanguageCodes.push(languageCode);
}
}
}

state.interaction.hints.forEach(function(hint) {
var audioTranslationsForHint =
hint.hintContent.getBindableAudioTranslations();
for (var languageCode in audioTranslationsForHint) {
if (allAudioLanguageCodes.indexOf(languageCode) === -1) {
allAudioLanguageCodes.push(languageCode);
}
}
});

if (state.interaction.solution != null) {
var audioTranslationsForSolution =
state.interaction.solution.explanation
.getBindableAudioTranslations();
for (var languageCode in audioTranslationsForSolution) {
if (allAudioLanguageCodes.indexOf(languageCode) === -1) {
allAudioLanguageCodes.push(languageCode);
}
}
}
}
return allAudioLanguageCodes;
};

States.prototype.getAllAudioTranslations = function(languageCode) {
var allAudioTranslations = {};
for (var stateName in this._states) {
var audioTranslationsForState =
this._states[stateName].content.getBindableAudioTranslations();
if (audioTranslationsForState.hasOwnProperty(languageCode)) {
allAudioTranslations[stateName] =
audioTranslationsForState[languageCode];
var state = this._states[stateName];
allAudioTranslations[stateName] = [];

var audioTranslationsForStateContent =
state.content.getBindableAudioTranslations();
if (audioTranslationsForStateContent.hasOwnProperty(languageCode)) {
allAudioTranslations[stateName].push(
audioTranslationsForStateContent[languageCode]);
}

state.interaction.answerGroups.forEach(function(answerGroup) {
var audioTranslationsForAnswerGroup =
answerGroup.outcome.feedback.getBindableAudioTranslations();
if (audioTranslationsForAnswerGroup.hasOwnProperty(languageCode)) {
allAudioTranslations[stateName].push(
audioTranslationsForAnswerGroup[languageCode]);
}
});

if (state.interaction.defaultOutcome != null) {
var audioTranslationsForDefaultOutcome =
state.interaction.defaultOutcome.feedback
.getBindableAudioTranslations();
if (audioTranslationsForDefaultOutcome.hasOwnProperty(languageCode)) {
allAudioTranslations[stateName].push(
audioTranslationsForDefaultOutcome[languageCode]);
}
}

state.interaction.hints.forEach(function(hint) {
var audioTranslationsForHint =
hint.hintContent.getBindableAudioTranslations();
if (audioTranslationsForHint.hasOwnProperty(languageCode)) {
allAudioTranslations[stateName].push(
audioTranslationsForHint[languageCode]);
}
});

if (state.interaction.solution != null) {
var audioTranslationsForSolution =
state.interaction.solution.explanation
.getBindableAudioTranslations();
if (audioTranslationsForSolution.hasOwnProperty(languageCode)) {
allAudioTranslations[stateName].push(
audioTranslationsForSolution[languageCode]);
}
}
}
return allAudioTranslations;
Expand Down
102 changes: 91 additions & 11 deletions core/templates/dev/head/domain/exploration/StatesObjectFactorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ describe('States object factory', function() {
feedback: [],
param_changes: []
},
hints: []
hints: [],
solution: null
},
param_changes: []
}
Expand All @@ -105,18 +106,80 @@ describe('States object factory', function() {
}
},
interaction: {
answer_groups: [],
answer_groups: [{
labelled_as_correct: false,
outcome: {
dest: 'second state',
feedback: {
html: '<p>Good.</p>',
audio_translations: {
zh: {
filename: 'myfile4.mp3',
file_size_bytes: 1.1,
needs_update: false
}
}
},
param_changes: []
},
rule_specs: [{
inputs: {
x: 20
},
rule_type: 'Equals'
}]
}],
confirmed_unclassified_answers: [],
customization_args: {},
default_outcome: {
dest: 'new state',
feedback: [],
feedback: {
html: '<p>Feedback</p>',
audio_translations: {
he: {
filename: 'myfile10.mp3',
file_size_bytes: 0.5,
needs_update: false
}
}
},
param_changes: []
},
hints: [],
hints: [{
hint_content: {
html: '<p>Here is a hint.</p>',
audio_translations: {
es: {
filename: 'myfile5.mp3',
file_size_bytes: 0.7,
needs_update: false
},
zh: {
filename: 'myfile6.mp3',
file_size_bytes: 0.9,
needs_update: false
},
'hi-en': {
filename: 'myfile8.mp3',
file_size_bytes: 1.2,
needs_update: false
}
}
}
}, {
hint_content: {
html: '<p>Here is another hint.</p>',
audio_translations: {
cs: {
filename: 'myfile7.mp3',
file_size_bytes: 0.2,
needs_update: false
}
}
}
}],
id: 'TextInput'
},
hints: [],
param_changes: []
},
'second state': {
Expand All @@ -140,9 +203,22 @@ describe('States object factory', function() {
param_changes: []
},
hints: [],
solution: {
answer_is_exclusive: false,
correct_answer: 'answer',
explanation: {
html: '<p>This is an explanation.</p>',
audio_translations: {
de: {
filename: 'myfile9.mp3',
file_size_bytes: 0.5,
needs_update: false
}
}
}
},
id: 'TextInput'
},
hints: [],
param_changes: []
}
}
Expand Down Expand Up @@ -184,23 +260,27 @@ describe('States object factory', function() {
it('should correctly get all audio language codes in states', function() {
var statesWithAudio = ssof.createFromBackendDict(statesWithAudioDict);
expect(statesWithAudio.getAllAudioLanguageCodes())
.toEqual(['en', 'hi-en']);
.toEqual(['en', 'hi-en', 'zh', 'he', 'es', 'cs', 'de']);
});

it('should correctly get all audio translations in states', function() {
var statesWithAudio = ssof.createFromBackendDict(statesWithAudioDict);
expect(statesWithAudio.getAllAudioTranslations('hi-en'))
.toEqual({
'first state': atof.createFromBackendDict({
'first state': [atof.createFromBackendDict({
filename: 'myfile3.mp3',
file_size_bytes: 0.8,
needs_update: false
}),
'second state': atof.createFromBackendDict({
}), atof.createFromBackendDict({
filename: 'myfile8.mp3',
file_size_bytes: 1.2,
needs_update: false
})],
'second state': [atof.createFromBackendDict({
filename: 'myfile2.mp3',
file_size_bytes: 0.8,
needs_update: false
})
})]
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@
<script src="{{TEMPLATE_DIR_PREFIX}}/pages/exploration_player/StatsReportingService.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/pages/exploration_player/FatigueDetectionService.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/pages/exploration_player/NumberAttemptsService.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/pages/exploration_player/AudioTranslationLanguageService.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/pages/exploration_player/AudioTranslationManagerService.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/pages/exploration_player/AudioBarDirective.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/pages/exploration_player/AudioPreloaderService.js"></script>
Expand Down
Loading

0 comments on commit 6adb3f9

Please sign in to comment.