diff --git a/Cargo.lock b/Cargo.lock index f86715e0..3c4956e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3360,6 +3360,7 @@ dependencies = [ "eyre", "k", "ndarray 0.15.6", + "pinyin", "pyo3", "rand 0.9.1", "rerun", @@ -8451,6 +8452,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pinyin" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f2611cd06a1ac239a0cea4521de9eb068a6ca110324ee00631aa68daa74fc0" + [[package]] name = "piper" version = "0.2.4" diff --git a/examples/speech-to-text/whisper-dev.yml b/examples/speech-to-text/whisper-dev.yml index 1742bd9f..1c2759b0 100644 --- a/examples/speech-to-text/whisper-dev.yml +++ b/examples/speech-to-text/whisper-dev.yml @@ -28,7 +28,7 @@ nodes: # USE_MODELSCOPE_HUB: true - id: dora-rerun - build: cargo build -p dora-rerun --release + build: pip install -e ../../node-hub/dora-rerun path: dora-rerun inputs: original_text: dora-distil-whisper/text diff --git a/node-hub/dora-rerun/Cargo.toml b/node-hub/dora-rerun/Cargo.toml index d777d312..2070f90d 100644 --- a/node-hub/dora-rerun/Cargo.toml +++ b/node-hub/dora-rerun/Cargo.toml @@ -28,6 +28,7 @@ pyo3 = { workspace = true, features = [ ], optional = true } bytemuck = "1.20.0" rand = "0.9.1" +pinyin = "0.10.0" [lib] diff --git a/node-hub/dora-rerun/src/lib.rs b/node-hub/dora-rerun/src/lib.rs index 66d731f2..48037074 100644 --- a/node-hub/dora-rerun/src/lib.rs +++ b/node-hub/dora-rerun/src/lib.rs @@ -12,6 +12,7 @@ use dora_node_api::{ }; use eyre::{bail, eyre, Context, Result}; +use pinyin::ToPinyin; use rerun::{ components::ImageBuffer, external::log::warn, ImageFormat, Points2D, Points3D, SpawnOptions, }; @@ -315,7 +316,24 @@ pub fn lib_main() -> Result<()> { let buffer: StringArray = data.to_data().into(); buffer.iter().try_for_each(|string| -> Result<()> { if let Some(str) = string { - rec.log(id.as_str(), &rerun::TextLog::new(str)) + let chars = str.chars().collect::>(); + let mut new_string = vec![]; + for char in chars { + // Check if the character is a Chinese character + if char.is_ascii() || char.is_control() { + new_string.push(char); + continue; + } + // If it is a Chinese character, replace it with its pinyin + if let Some(pinyin) = char.to_pinyin() { + for char in pinyin.with_tone().chars() { + new_string.push(char); + } + new_string.push(' '); + } + } + let pinyined_str = new_string.iter().collect::(); + rec.log(id.as_str(), &rerun::TextLog::new(pinyined_str)) .wrap_err("Could not log text") } else { Ok(())