mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-02 16:38:14 +00:00
Adding skeleton of deployable service
This commit is contained in:
1 parent
6fdbaa2ad1
commit
9f73582091
6 files changed
+108
-2
No files matched your search
Generated
+13
@@ -1742,6 +1742,19 @@ name = "traitobject"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "tts_service"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"hound 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rocket 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rocket_contrib 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tch 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typeable"
|
||||
version = "0.1.2"
|
||||
|
||||
@@ -8,11 +8,13 @@ authors = [ "Brandon Thomas <bt@brand.io>",
|
||||
members = [
|
||||
"tacotron_melgan",
|
||||
"tacotron_tensorflow",
|
||||
"tts_service",
|
||||
"voice_converter_sidecar",
|
||||
]
|
||||
default-members = [
|
||||
"tacotron_melgan",
|
||||
"tacotron_tensorflow",
|
||||
"tts_service",
|
||||
"voice_converter_sidecar",
|
||||
]
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use model::{TacoMelModel, load_wrapped_tensor_file, load_model_file, audio_signa
|
||||
use tch::nn::Module;
|
||||
use melgan::audio_tensor_to_audio_signal;
|
||||
use tch::Tensor;
|
||||
use std::panic;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Message {
|
||||
@@ -19,8 +20,20 @@ fn get_index() -> String {
|
||||
|
||||
#[get("/tts?<text>")]
|
||||
fn get_tts(model: State<TacoMelModel>, text: &RawStr) -> Content<Vec<u8>> {
|
||||
let audio_bytes = model.inner().run_tts_audio(text.as_str());
|
||||
Content(ContentType::new("audio", "wav"), audio_bytes)
|
||||
|
||||
let result = panic::catch_unwind(|| {
|
||||
let audio_bytes = model.inner().run_tts_audio(text.as_str());
|
||||
audio_bytes
|
||||
});
|
||||
|
||||
match result {
|
||||
Err(_) => {
|
||||
Content(ContentType::Plain, "there was an error".as_bytes().to_vec())
|
||||
},
|
||||
Ok(audio_bytes) => {
|
||||
Content(ContentType::new("audio", "wav"), audio_bytes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn print_mel(tensor: &Tensor, i: i64) {
|
||||
@@ -46,6 +59,7 @@ fn print_audio_signal(signal: &Vec<i16>, i: usize) {
|
||||
fn get_tts_test() -> Content<Vec<u8>> {
|
||||
println!("Loading melgan model...");
|
||||
let melgan_filename = "/home/bt/dev/tacotron-melgan/shared_melgan_container.pt";
|
||||
let melgan_filename = "/home/bt/dev/tacotron-melgan/shared_melgan_container2.pt";
|
||||
let melgan_model = load_model_file(melgan_filename);
|
||||
|
||||
println!("Loading mel...");
|
||||
@@ -101,6 +115,7 @@ pub fn run_server() {
|
||||
//let melgan = "/home/bt/dev/voder/tacotron_melgan/melgan_jit_model_voder_c0cac635.pt";
|
||||
let melgan = "/home/bt/dev/voder/tacotron_melgan/melgan_container2.pt";
|
||||
let melgan = "/home/bt/dev/tacotron-melgan/shared_melgan_container.pt";
|
||||
let melgan = "/home/bt/dev/tacotron-melgan/shared_melgan_container2.pt";
|
||||
let model = TacoMelModel::create(
|
||||
tacotron,
|
||||
melgan);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "tts_service"
|
||||
version = "0.0.1"
|
||||
authors = [ "Brandon Thomas <bt@brand.io>",
|
||||
"Brandon Thomas <echelon@gmail.com>" ]
|
||||
|
||||
[[bin]]
|
||||
name = "tts_service"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
hound = "3.4.0" # wav codec
|
||||
rocket = "0.4.2" # http server
|
||||
rocket_contrib = "0.4.2" # http server
|
||||
serde = "1.0.104"
|
||||
serde_derive = "1.0.104"
|
||||
serde_json = "1.0.44"
|
||||
tch = "0.1.3" # libtorch bindings (pytorch)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
TTS Service
|
||||
===========
|
||||
This is the deployable TTS service. Whereas most of the other sub-projects are
|
||||
experimental, this one is meant for production deploys.
|
||||
|
||||
Experiments for this are conducted in the `tacotron_melgan` sub-project.
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
|
||||
#[macro_use] extern crate rocket;
|
||||
#[macro_use] extern crate rocket_contrib;
|
||||
#[macro_use] extern crate serde_derive;
|
||||
extern crate hound;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
extern crate tch;
|
||||
|
||||
use rocket::http::{RawStr, ContentType};
|
||||
use rocket::response::content::Content;
|
||||
use rocket::{Request, State, Response};
|
||||
use rocket_contrib::json::{Json, JsonValue};
|
||||
use tch::CModule;
|
||||
use tch::Tensor;
|
||||
use tch::nn::Module;
|
||||
use tch::nn::ModuleT;
|
||||
|
||||
#[catch(404)]
|
||||
fn not_found(_req: &Request) -> String {
|
||||
"404 Not Found".into()
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
pub fn get_root() -> String {
|
||||
"Hello World".into()
|
||||
}
|
||||
|
||||
#[get("/readiness")]
|
||||
pub fn get_readiness() -> String {
|
||||
"Ready".into()
|
||||
}
|
||||
|
||||
#[get("/liveness")]
|
||||
pub fn get_liveness() -> String {
|
||||
"Live".into()
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
rocket::ignite()
|
||||
.mount("/", routes![
|
||||
get_root,
|
||||
get_readiness,
|
||||
get_liveness,
|
||||
])
|
||||
//.manage(model)
|
||||
.register(catchers![not_found])
|
||||
.launch();
|
||||
}
|
||||
Reference in new issue
Block a user