index tts stash save

This commit is contained in:
jhqxxx
2026-01-30 22:04:23 +08:00
parent 53791efa80
commit e3944588fc
39 changed files with 4613 additions and 137 deletions
+13 -4
View File
@@ -1,22 +1,31 @@
// use std::io::Cursor;
use aha::utils::audio_utils::create_hann_window;
use std::time::Instant;
use aha::utils::{audio_utils::create_hann_window, tensor_utils::interpolate_nearest_1d};
use anyhow::Result;
use candle_core::DType;
use candle_core::{DType, Tensor};
// use symphonia::core::io::MediaSourceStream;
#[test]
fn messy_test() -> Result<()> {
// RUST_BACKTRACE=1 cargo test -F cuda,ffmpeg messy_test -r -- --nocapture
let device = &candle_core::Device::Cpu;
let t = Tensor::arange(0.0f32, 40.0, device)?.broadcast_as((1, 40, 40))?;
println!("t: {}", t);
let i_start = Instant::now();
let t_inter = interpolate_nearest_1d(&t, 20)?;
let i_duration = i_start.elapsed();
println!("Time elapsed in interpolate_nearest_1d is: {:?}", i_duration);
println!("t_inter: {}", t_inter);
// let url = "https://sis-sample-audio.obs.cn-north-1.myhuaweicloud.com/16k16bit.mp3";
// let client = reqwest::blocking::Client::new();
// let response = client.get(url).send()?;
// let vec_u8 = response.bytes()?.to_vec();
// let mut content = Cursor::new(vec_u8);
// let mss = MediaSourceStream::new(Box::new(content), Default::default());
let window = create_hann_window(400, DType::F32, device)?;
println!("window: {}", window);
// let window = create_hann_window(400, DType::F32, device)?;
// println!("window: {}", window);
// let audio_path = "file:///home/jhq/Videos/voice_01.wav";
// let audio_path = "/home/jhq/Videos/zh.mp3";
// let audio_path = "/home/jhq/Videos/zh.mp3";
+48
View File
@@ -0,0 +1,48 @@
use std::time::Instant;
use anyhow::Result;
use aha::models::index_tts2::{generate::IndexTTS2Generate, utils::download_index_tts2_need_model};
use aha_openai_dive::v1::resources::chat::ChatCompletionParameters;
#[tokio::test]
async fn index_tts2_generate() -> Result<()> {
// RUST_BACKTRACE=1 cargo test -F cuda index_tts2_generate -r -- --nocapture
let save_dir =
aha::utils::get_default_save_dir().ok_or(anyhow::anyhow!("Failed to get save dir"))?;
let _ = download_index_tts2_need_model(Some(&save_dir)).await?;
let model_path = format!("{}/IndexTeam/IndexTTS-2", save_dir);
let message = r#"
{
"model": "index-tts2",
"messages": [
{
"role": "user",
"content": [
{
"type": "audio",
"audio_url":
{
"url": "file:///home/jhq/Videos/voice_01.wav"
}
},
{
"type": "text",
"text": "你好啊"
}
]
}
]
}
"#;
let mes: ChatCompletionParameters = serde_json::from_str(message)?;
let i_start = Instant::now();
let mut voxcpm_generate = IndexTTS2Generate::init(&model_path, None, None)?;
let i_duration = i_start.elapsed();
println!("Time elapsed in load model is: {:?}", i_duration);
let i_start = Instant::now();
let generate = voxcpm_generate.generate(mes)?;
let i_duration = i_start.elapsed();
println!("Time elapsed in generate is: {:?}", i_duration);
Ok(())
}
+39 -1
View File
@@ -1,6 +1,6 @@
use std::collections::HashMap;
use aha::utils::{find_type_files, get_device};
use aha::utils::{find_type_files, get_device, read_pth_tensor_info_cycle};
use anyhow::Result;
use candle_core::{Device, pickle::read_all_with_key, safetensors};
use candle_nn::VarBuilder;
@@ -197,3 +197,41 @@ fn qwen3_weight() -> Result<()> {
println!("model_list: {:?}", model_list);
Ok(())
}
#[test]
fn index_tts2_weight() -> Result<()> {
let save_dir: String =
aha::utils::get_default_save_dir().ok_or(anyhow::anyhow!("Failed to get save dir"))?;
let model_path = format!("{}/IndexTeam/IndexTTS-2/", save_dir);
let s2mel_path = model_path+ "/s2mel.pth";
// let wac2vec2_path = model_path+ "/wav2vec2bert_stats.pt";
// let model_path = format!("{}/iic/speech_campplus_sv_zh-cn_16k-common/", save_dir);
// let campplus_path = model_path+ "/campplus_cn_common.bin";
// let model_list = find_type_files(&model_path, "safetensors")?;
let model_list = vec![s2mel_path];
// let mut dict_to_hashmap = HashMap::new();
// let mut dtype = candle_core::DType::F32;
for m in model_list {
// let dict = read_all_with_key(m, Some("state_dict"))?;
// let dict = read_all_with_key(m, Some("net"))?;
let dict = read_pth_tensor_info_cycle(m, Some("net.cfm"))?;
// dtype = dict[0].1.dtype();
for (k, v) in dict {
// if k.contains("model") {
// println!("key: {}, tensor shape: {:?}", k, v);
// }
// dict_to_hashmap.insert(k, v);
println!("key: {}, tensor shape: {:?}", k, v);
}
}
// let device = Device::Cpu;
// let semantic_codec_path = save_dir.to_string() + "/amphion/MaskGCT/semantic_codec/model.safetensors" ;
// let model_list = vec![semantic_codec_path];
// for m in model_list {
// let weights = safetensors::load(m, &device)?;
// for (key, tensor) in weights.iter() {
// println!("=== {} === {:?}", key, tensor.shape());
// }
// }
Ok(())
}