hack to work on local and prod environments

This commit is contained in:
Brandon Thomas committed 2016-08-26 01:51:16 -04:00
1 parent 6c0c0118ff
commit 6ada19f32c
4 files changed
+48 -10

No files matched your search

+3
View File
@@ -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"
+36 -7
View File
@@ -1,5 +1,6 @@
// Copyright (c) 2016 Brandon Thomas <bt@brand.io>
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<Config> {
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<String, Error> {
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<String, Error> {
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() },
}
}
+3 -3
View File
@@ -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)
+6
View File
@@ -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) => {