diff --git a/config.toml b/config.toml index 2da8d2d55a..c10843ec3e 100644 --- a/config.toml +++ b/config.toml @@ -1,5 +1,8 @@ # Various configs +# TODO: This 'hostname' key is present only as a hack. +hostname = "" + # Sound paths in development and production environments sound_path_development = "/home/bt/Dropbox/jungle.horse/sounds" sound_path_production = "./sounds" diff --git a/src/config.rs b/src/config.rs index 99a6c687c3..0db01ee742 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,6 @@ // Copyright (c) 2016 Brandon Thomas +use resolve::hostname; use std::fs::File; use std::io::Error; use std::io::prelude::*; @@ -7,6 +8,11 @@ use toml; #[derive(Debug, RustcEncodable, RustcDecodable)] pub struct Config { + /// Machine hostname + /// TODO: This being public is a total hack. + /// Really, this shouldn't even be in the config. + pub hostname: String, + pub sound_path_development: String, pub sound_path_production: String, pub phoneme_dictionary_file_development: String, @@ -14,21 +20,44 @@ pub struct Config { } impl Config { + /// Static CTOR. pub fn read(filename: &str) -> Option { - match Config::read_file(filename) { + match read_file(filename) { Err(_) => None, Ok(contents) => { let value = toml::Parser::new(&contents).parse().unwrap(); - toml::decode(toml::Value::Table(value)) + let mut config = toml::decode(toml::Value::Table(value)); + + config.map(|mut c: Config| { + c.hostname = get_hostname(); + c + }) } } } - fn read_file(filename: &str) -> Result { - let mut file = try!(File::open(filename)); - let mut buf = String::new(); - try!(file.read_to_string(&mut buf)); - Ok(buf) + /// Get the sound directory path. + pub fn get_sound_path(&self) -> String { + if self.hostname == "x16" { + self.sound_path_development.clone() + } else { + self.sound_path_production.clone() + } + } +} + +fn read_file(filename: &str) -> Result { + let mut file = try!(File::open(filename)); + let mut buf = String::new(); + try!(file.read_to_string(&mut buf)); + Ok(buf) +} + +// TODO: This is a total hack. +fn get_hostname() -> String { + match hostname::get_hostname() { + Ok(s) => { s.to_string() }, + Err(_) => { "".to_string() }, } } diff --git a/src/main.rs b/src/main.rs index e000e6eeb5..cdcceccc4b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,7 +60,7 @@ fn main() { let config = Config::read("./config.toml").unwrap(); VocabularyLibrary::read_from_directory( - Path::new(&config.sound_path_development)); + Path::new(&config.get_sound_path())); get_hostname(); @@ -82,7 +82,7 @@ fn get_port(matches: &ArgMatches, default_port: u16) -> u16 { } fn start_server(config: &Config, port: u16, synthesizer: Synthesizer) { - let audio_path = &config.sound_path_development; + let audio_path = &config.get_sound_path(); let file_path = "./web"; let index = "index.html"; @@ -118,7 +118,7 @@ fn create_synthesizer(config: &Config) -> Synthesizer { let arpabet_dictionary = ArpabetDictionary::load_from_file( &config.phoneme_dictionary_file_development).unwrap(); - let audiobank = Audiobank::new(&config.sound_path_development); + let audiobank = Audiobank::new(&config.get_sound_path()); info!("Building Synthesizer..."); Synthesizer::new(arpabet_dictionary, audiobank) diff --git a/src/synthesizer.rs b/src/synthesizer.rs index bb6b0606b7..6b5c95bcd5 100644 --- a/src/synthesizer.rs +++ b/src/synthesizer.rs @@ -84,6 +84,12 @@ impl Synthesizer { match self.audiobank.get_phoneme(speaker, &phoneme) { None => { // TODO: ERROR (maybe add static based on word length!) + match self.audiobank.get_misc("beep") { + None => {}, + Some(waveform_data) => { + concatenated_waveform.extend(waveform_data); + }, + } continue; }, Some(waveform_data) => {