Skip to content

Commit

Permalink
Add synthesis text length recommendation
Browse files Browse the repository at this point in the history
  • Loading branch information
BenAAndrew committed Sep 18, 2021
1 parent 098b04f commit f0b0b8f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions application/static/synthesis.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<div class="form-group">
<label for="text">Text</label><br>
<span id="text_input"></span>
<span id="text_label"></span>
</div>
<button type="button" class="collapsible" id="advanced">Advanced Options ∨</button>
<div class="content">
Expand Down
24 changes: 24 additions & 0 deletions application/static/synthesis.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ function addTextInput(value){
section.appendChild(createTextInput(value));
}

// Text reccomendation
// Based on the assumption WPM is 150 (one word every 0.4s)
// and that good quality is 2-8 seconds (very rough guess)
LOW_TEXT_THRESHOLD = 5;
OK_TEXT_THRESHOLD = 20;

function labelTextRecommendation(){
var text = document.getElementById("text").value;
var words = text.trim().split(" ").length;
var advice = "";

if(words < LOW_TEXT_THRESHOLD){
advice = "Text may be too short 🙁";
} else if(words < OK_TEXT_THRESHOLD){
advice = "Text is a good length 🙂";
} else{
advice = "Text may be too long 🙁";
}

document.getElementById("text_label").innerHTML = advice;
}

function changeTextMethod(){
method = document.getElementById("text_method").value;
section = document.getElementById("text_input");
Expand All @@ -24,6 +46,7 @@ function changeTextMethod(){
if(method == "single" || method == "multi"){
var element = createTextInput();
if(method == "single"){
element.onkeyup = function() { labelTextRecommendation(); };
section.appendChild(element);
} else {
var container = document.createElement("span");
Expand All @@ -44,6 +67,7 @@ function changeTextMethod(){
element.name = "text";
element.rows = "4";
element.required = true;
element.onkeyup = function() { labelTextRecommendation(); };
section.appendChild(element);
}

Expand Down

0 comments on commit f0b0b8f

Please sign in to comment.