Skip to content

Commit

Permalink
Review text extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
rodfersou committed Jun 14, 2016
1 parent e76dd39 commit b1ef985
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
1.0b2 (unreleased)
------------------

- Nothing changed yet.
- Review text extraction.
[rodfersou]


1.0b1 (2016-06-14)
Expand Down
20 changes: 18 additions & 2 deletions src/collective/texttospeech/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ var MainView = (function() {
this.paused = true;
this.$button.attr('value', this.label_stopped);
};
MainView.prototype.extract_text = function() {
var i, len, ref, results, paragraph;
// get title, description and all paragraphs
ref = $('#content .documentFirstHeading, #content .documentDescription, #content p');
results = [];
for (i = 0, len = ref.length; i < len; i++) {
// take out blank spaces
paragraph = $(ref[i]).text().replace(/\s+/g, ' ').trim();
// ignore empty lines
if (paragraph.length > 0) {
// take out ending periods
results.push(paragraph.replace(/\.$/, ''));
}
}
// add again ending periods
return results.join('. ');
};
MainView.prototype.play_pause = function(e) {
e.preventDefault();
if (this.playing) {
Expand All @@ -40,8 +57,7 @@ var MainView = (function() {
}
} else {
responsiveVoice.speak(
// remove spaces to avoid issues with some Firefox versions
$('#content').text().replace(/\s+/g, ' ').trim(),
this.extract_text(),
this.voice, {
onstart: $.proxy(this.onstart, this),
onend: $.proxy(this.onend, this)
Expand Down

0 comments on commit b1ef985

Please sign in to comment.