環境変数で読み込むことにした

This commit is contained in:
tuna2134
2024-09-10 09:40:49 +00:00
parent 30a5be0878
commit 3bbaf19e36
6 changed files with 16 additions and 5 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@ target
models/*.onnx models/*.onnx
models/*.json models/*.json
venv venv
.env

7
Cargo.lock generated
View File

@@ -357,6 +357,12 @@ dependencies = [
"crypto-common", "crypto-common",
] ]
[[package]]
name = "dotenvy"
version = "0.15.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
[[package]] [[package]]
name = "either" name = "either"
version = "1.13.0" version = "1.13.0"
@@ -1614,6 +1620,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"axum", "axum",
"dotenvy",
"sbv2_core", "sbv2_core",
"serde", "serde",
"tokio", "tokio",

Binary file not shown.

View File

@@ -6,6 +6,7 @@ edition = "2021"
[dependencies] [dependencies]
anyhow.workspace = true anyhow.workspace = true
axum = "0.7.5" axum = "0.7.5"
dotenvy = "0.15.7"
sbv2_core = { version = "0.1.0", path = "../sbv2_core" } sbv2_core = { version = "0.1.0", path = "../sbv2_core" }
serde = { version = "1.0.210", features = ["derive"] } serde = { version = "1.0.210", features = ["derive"] }
tokio = { version = "1.40.0", features = ["full"] } tokio = { version = "1.40.0", features = ["full"] }

View File

@@ -7,6 +7,7 @@ use axum::{
}; };
use sbv2_core::tts::TTSModel; use sbv2_core::tts::TTSModel;
use serde::Deserialize; use serde::Deserialize;
use std::env;
use std::sync::Arc; use std::sync::Arc;
use tokio::sync::Mutex; use tokio::sync::Mutex;
@@ -28,9 +29,9 @@ async fn synthesize(
tts_model tts_model
} else { } else {
*tts_model = Some(TTSModel::new( *tts_model = Some(TTSModel::new(
"models/debert.onnx", env::var("BERT_MODEL_PATH")?,
"models/model_opt.onnx", env::var("MAIN_MODEL_PATH")?,
"models/style_vectors.json", env::var("STYLE_VECTORS_PATH")?,
)?); )?);
tts_model.as_ref().unwrap() tts_model.as_ref().unwrap()
}; };
@@ -47,6 +48,7 @@ struct AppState {
#[tokio::main] #[tokio::main]
async fn main() -> anyhow::Result<()> { async fn main() -> anyhow::Result<()> {
dotenvy::dotenv().ok();
let app = Router::new() let app = Router::new()
.route("/", get(|| async { "Hello, World!" })) .route("/", get(|| async { "Hello, World!" }))
.route("/synthesize", post(synthesize)) .route("/synthesize", post(synthesize))

View File

@@ -2,7 +2,7 @@ import requests
res = requests.post('http://localhost:3000/synthesize', json={ res = requests.post('http://localhost:3000/synthesize', json={
"text": "眠たい" "text": "おはよう"
}) })
res.raise_for_status() res.raise_for_status()
with open('output.wav', 'wb') as f: with open('output.wav', 'wb') as f: