mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-19 16:15:04 +00:00
use_phonemes, use_words options
This commit is contained in:
1 parent
de8a8636b4
commit
04c06bbba4
5 files changed
+85
-38
No files matched your search
@@ -8,7 +8,6 @@ use iron::Handler;
|
||||
use iron::headers::{ETag, EntityTag, Headers, IfNoneMatch};
|
||||
use iron::mime::Mime;
|
||||
use iron::prelude::*;
|
||||
//use params::Params;
|
||||
use iron::status;
|
||||
use router::Router;
|
||||
use rustc_serialize::json;
|
||||
@@ -23,6 +22,7 @@ use std::io::Cursor;
|
||||
use std::io::Read;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::sync::RwLock;
|
||||
use super::error_filter::build_error;
|
||||
@@ -30,8 +30,10 @@ use synthesizer::Synthesizer;
|
||||
use urlencoded::UrlEncodedQuery;
|
||||
use words::split_sentence;
|
||||
|
||||
const SPEAKER_PARAM : &'static str = "v";
|
||||
const SENTENCE_PARAM : &'static str = "s";
|
||||
const SPEAKER_PARAM : &'static str = "v";
|
||||
const USE_PHONEMES_PARAM: &'static str = "up";
|
||||
const USE_WORDS_PARAM: &'static str = "uw";
|
||||
const VOLUME_PARAM : &'static str = "vol";
|
||||
|
||||
/// Represents a request to this endpoint.
|
||||
@@ -45,11 +47,11 @@ struct SpeakRequest {
|
||||
/** An optional volume multiplier. */
|
||||
pub volume: Option<f32>,
|
||||
|
||||
/** Whether to use words. */
|
||||
pub use_words: bool,
|
||||
|
||||
/** Whether to use phonemes. */
|
||||
pub use_phonemes: bool,
|
||||
|
||||
/** Whether to use words. */
|
||||
pub use_words: bool,
|
||||
}
|
||||
|
||||
enum SpeakerRequestError {
|
||||
@@ -78,7 +80,7 @@ impl SpeakRequest {
|
||||
|
||||
// Get the request sentence and speaker.
|
||||
// TODO: Cleanup
|
||||
let (sentence, speaker, volume) = match http_request.get_ref::<UrlEncodedQuery>() {
|
||||
match http_request.get_ref::<UrlEncodedQuery>() {
|
||||
Err(_) => { return sentence_error; },
|
||||
Ok(ref map) => {
|
||||
let sen = match map.get(SENTENCE_PARAM) {
|
||||
@@ -116,34 +118,45 @@ impl SpeakRequest {
|
||||
},
|
||||
};
|
||||
|
||||
(sen, spk, volume)
|
||||
},
|
||||
};
|
||||
|
||||
/*let (use_words, use_phonemes) = match http_request.get_ref::<Params>() {
|
||||
None => {
|
||||
(false, false)
|
||||
},
|
||||
Some(map) => {
|
||||
match map.find("use_words") {
|
||||
Some(_e) => {
|
||||
println!(">>> FOUND");
|
||||
let use_phonemes = match map.get(USE_PHONEMES_PARAM) {
|
||||
None => { true },
|
||||
Some(list) => {
|
||||
match list.get(0) {
|
||||
None => { return speaker_error; },
|
||||
Some(s) => {
|
||||
match FromStr::from_str(s) {
|
||||
Ok(b) => b,
|
||||
Err(_) => { return speaker_error; },
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
println!(">>> NOT FOUND");
|
||||
},
|
||||
}
|
||||
(true, true)
|
||||
},
|
||||
};*/
|
||||
};
|
||||
|
||||
Ok(SpeakRequest {
|
||||
sentence: sentence,
|
||||
speaker: speaker,
|
||||
volume: volume,
|
||||
use_words: false,
|
||||
use_phonemes: true,
|
||||
})
|
||||
let use_words = match map.get(USE_WORDS_PARAM) {
|
||||
None => { true },
|
||||
Some(list) => {
|
||||
match list.get(0) {
|
||||
None => { return speaker_error; },
|
||||
Some(s) => {
|
||||
match FromStr::from_str(s) {
|
||||
Ok(b) => b,
|
||||
Err(_) => { return speaker_error; },
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(SpeakRequest {
|
||||
sentence: sen,
|
||||
speaker: spk,
|
||||
volume: volume,
|
||||
use_phonemes: use_phonemes,
|
||||
use_words: use_words,
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ extern crate hound;
|
||||
extern crate iron;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
//extern crate params;
|
||||
extern crate regex;
|
||||
extern crate resolve;
|
||||
extern crate router;
|
||||
|
||||
@@ -40,7 +40,11 @@
|
||||
speaker = $('select').val(),
|
||||
volume = $('input#vol').val(),
|
||||
query = encodeURIComponent(sentence),
|
||||
url = '/speak?v=' + speaker + '&s=' + query + '&vol=' + volume;
|
||||
url = '/speak?v=' + speaker
|
||||
+ '&s=' + query
|
||||
+ '&vol=' + volume
|
||||
+ '&up=' + $('#use_phonemes').prop('checked')
|
||||
+ '&uw=' + $('#use_words').prop('checked');
|
||||
|
||||
ev.preventDefault();
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
|
||||
$('input#vol').val(volume);
|
||||
|
||||
$('#use_phonemes').prop('use_phonemes', Url.getUsePhonemes());
|
||||
$('#use_words').prop('use_words', Url.getUseWords());
|
||||
|
||||
Library.load(function(library) { Ui.libraryLoadCallback(library); });
|
||||
Sound.install();
|
||||
|
||||
|
||||
+32
-4
@@ -13,6 +13,12 @@
|
||||
/** JSON key for the `volume` param. */
|
||||
_VOLUME_KEY: 'vol',
|
||||
|
||||
/** JSON key for the `use_phonemes` param. */
|
||||
_USE_PHONEMES_KEY: 'up',
|
||||
|
||||
/** JSON key for the `use_words` param. */
|
||||
_USE_WORDS_KEY: 'uw',
|
||||
|
||||
/** Get the sentence from the `window.location`. */
|
||||
getSentence: function() {
|
||||
var state = this.parseState(window.location),
|
||||
@@ -45,16 +51,36 @@
|
||||
}
|
||||
},
|
||||
|
||||
/** Get the "use phonemes" from the `window.location`. */
|
||||
getUsePhonemes: function() {
|
||||
var state = this.parseState(window.location);
|
||||
if (!state || !(this._USE_PHONEMES_KEY in state)) {
|
||||
return null;
|
||||
} else {
|
||||
return state[this._USE_PHONEMES_KEY];
|
||||
}
|
||||
},
|
||||
|
||||
/** Get the "use words" from the `window.location`. */
|
||||
getUseWords: function() {
|
||||
var state = this.parseState(window.location);
|
||||
if (!state || !(this._USE_WORDS_KEY in state)) {
|
||||
return null;
|
||||
} else {
|
||||
return state[this._USE_WORDS_KEY];
|
||||
}
|
||||
},
|
||||
|
||||
// TODO: Independent functions to set both speaker and sentence separately.
|
||||
/** Set the `window.history` speaker, volume, and sentence. */
|
||||
setState: function(speaker, rawSentence, volume) {
|
||||
var urlHash = this.fromParams(speaker, rawSentence, volume);
|
||||
/** Set the `window.history` speaker, sentence, phoneme use, and word use. */
|
||||
setState: function(speaker, rawSentence, volume, usePhonemes, useWords) {
|
||||
var urlHash = this.fromParams(speaker, rawSentence, volume, usePhonemes, useWords);
|
||||
console.log('set state, urlhash = ', urlHash);
|
||||
window.history.replaceState(null, null, urlHash);
|
||||
},
|
||||
|
||||
/** Encode a speaker and sentence in a URL hash. */
|
||||
fromParams: function(speaker, rawSentence, volume) {
|
||||
fromParams: function(speaker, rawSentence, volume, usePhonemes, useWords) {
|
||||
var cleanedSentence = SentenceHelper.cleanSentence(rawSentence),
|
||||
cleanedSpeaker = speaker, // TODO: Check against speakers.
|
||||
cleanedVolume = volume, // TODO: Filter invalid values.
|
||||
@@ -65,6 +91,8 @@
|
||||
state[this._SPEAKER_KEY] = cleanedSpeaker;
|
||||
state[this._SENTENCE_KEY] = cleanedSentence;
|
||||
state[this._VOLUME_KEY] = cleanedVolume;
|
||||
state[this._USE_PHONEMES_KEY] = !!usePhonemes;
|
||||
state[this._USE_WORDS_KEY] = !!useWords;
|
||||
|
||||
json = JSON.stringify(state);
|
||||
|
||||
|
||||
Reference in new issue
Block a user