diff --git a/tts_service/models.toml b/tts_service/models.toml index 29fbe55af8..f9fc94a3f5 100644 --- a/tts_service/models.toml +++ b/tts_service/models.toml @@ -594,13 +594,6 @@ model_pipeline = "ArpabetGlowTtsMelgan" glow_tts = "glow-tts_neil_degrasse_tyson_ljstx_2020.07.05_expr-1_chkpt-2482.torchjit" melgan = "melgan_manyvoice2.0_2020-07-08_12d5838_9330.torchjit" -[[speakers]] -name = "Samuel L. Jackson" -slug = "samuel-l-jackson" -model_pipeline = "ArpabetGlowTtsMelgan" -glow_tts = "glow-tts_samuel_l_jackson_ljstx_2020.07.05_expr-1_chkpt-2444.torchjit" -melgan = "melgan_manyvoice2.0_2020-07-08_12d5838_9330.torchjit" - [[speakers]] name = "Bill Nye" slug = "bill-nye" diff --git a/tts_service/src/bonus_voices/config.rs b/tts_service/src/bonus_voices/config.rs index d921dd5ce0..f0318b84a2 100644 --- a/tts_service/src/bonus_voices/config.rs +++ b/tts_service/src/bonus_voices/config.rs @@ -1,3 +1,4 @@ +use anyhow::anyhow; use crate::AnyhowResult; use std::collections::HashMap; use std::fs; @@ -19,6 +20,7 @@ pub struct BonusEndpoint { } /// Mapping of all the voices. +#[derive(Clone)] pub struct BonusEndpointMappings { pub url_slug_to_voices: HashMap> } @@ -34,6 +36,9 @@ impl BonusEndpoints { let mut mappings = HashMap::new(); for endpoint in self.bonus_endpoints.iter() { + if mappings.contains_key(&endpoint.http_endpoint) { + return Err(anyhow!("Endpoint already present in mappings: {}", &endpoint.http_endpoint)); + } mappings.insert(endpoint.http_endpoint.to_string(), endpoint.voices.clone()); } diff --git a/tts_service/src/bonus_voices/endpoints.rs b/tts_service/src/bonus_voices/endpoints.rs index 410ccfcfaa..5301be238e 100644 --- a/tts_service/src/bonus_voices/endpoints.rs +++ b/tts_service/src/bonus_voices/endpoints.rs @@ -1,31 +1,33 @@ use actix_web::web::{ Data, Json, + Path, }; use actix_web::{ HttpRequest, get, }; -use std::sync::Arc; use crate::AppState; +use crate::endpoints::speakers::SpeakersResult; use crate::model::model_config::Speaker; +use std::sync::Arc; -/*#[get("/access/{key}")] +#[get("/access/{key}")] pub async fn get_dynamic_early_access_speakers( _request: HttpRequest, - path_data: web::Path<(String,)>, + path_data: Path<(String,)>, app_state: Data> ) -> std::io::Result> { - println!("GET /access"); - + let url_key = path_data.into_inner().0; let app_state = app_state.into_inner(); + let mappings = &app_state.bonus_endpoint_mappings; let early_access_voices = - app_state.model_configs.early_access_voices + mappings.url_slug_to_voices.get(&url_key) .as_ref() - .map_or(Vec::new(), |list| list.clone()); + .map_or(Vec::new(), |list| list.to_vec()); let mut early_access_speakers : Vec = Vec::new(); @@ -39,4 +41,3 @@ pub async fn get_dynamic_early_access_speakers( speakers: early_access_speakers, })) } -*/ \ No newline at end of file diff --git a/tts_service/src/endpoints/speakers.rs b/tts_service/src/endpoints/speakers.rs index 6ce29b2b93..9e9fa01de3 100644 --- a/tts_service/src/endpoints/speakers.rs +++ b/tts_service/src/endpoints/speakers.rs @@ -13,7 +13,7 @@ use crate::model::model_config::Speaker; #[derive(Serialize, Debug, Clone)] pub struct SpeakersResult { - speakers: Vec, + pub speakers: Vec, } #[get("/speakers")] diff --git a/tts_service/src/main.rs b/tts_service/src/main.rs index c9a8dcbfb7..3df2c440ac 100644 --- a/tts_service/src/main.rs +++ b/tts_service/src/main.rs @@ -40,7 +40,9 @@ use actix::{Addr, SyncArbiter, Context}; use arpabet::Arpabet; use arpabet::load_cmudict; use arpabet::load_from_file as arpabet_load_from_file; +use crate::bonus_voices::config::BonusEndpointMappings; use crate::bonus_voices::config::BonusEndpoints; +use crate::bonus_voices::endpoints::get_dynamic_early_access_speakers; use crate::database::connector::DatabaseConnector; use crate::database::sentence_recorder::SentenceRecorder; use crate::endpoints::helpers::stats_recorder::StatsRecorder; @@ -136,6 +138,9 @@ pub struct AppState { pub rate_limiter: Box, pub stats_recorder: StatsRecorder, pub allow_model_reload: bool, + + // Bonus voices for "early access" and rewards. + pub bonus_endpoint_mappings: BonusEndpointMappings, } /** Startup parameters for the server. */ @@ -240,6 +245,8 @@ pub fn main() -> AnyhowResult<()> { info!("Bonus endpoints: {:?}", bonus_endpoints); + let bonus_endpoint_mappings = bonus_endpoints.to_mappings()?; + let model_cache = ModelCache::new(&model_configs.model_locations); let rate_limiter : Box = if limiter_enabled { @@ -317,6 +324,7 @@ pub fn main() -> AnyhowResult<()> { rate_limiter, stats_recorder, allow_model_reload, + bonus_endpoint_mappings, }; let server_args = ServerArgs { @@ -418,6 +426,7 @@ async fn run_server(app_state: AppState, server_args: ServerArgs) -> std::io::Re .service(get_service_settings) .service(get_speakers) .service(get_early_access_speakers) + .service(get_dynamic_early_access_speakers) .service(get_words) .app_data(arc.clone()) )