aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml1
-rw-r--r--help.txt1
-rw-r--r--src/args.rs14
-rw-r--r--src/main.rs12
5 files changed, 30 insertions, 5 deletions
diff --git a/Cargo.lock b/Cargo.lock
index be68723..8b4decf 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -576,6 +576,7 @@ name = "dumb-voice-protocol"
version = "0.1.0"
dependencies = [
"clap",
+ "pinyin",
"tokio",
"tracing-subscriber",
"vtx-engine",
@@ -1600,6 +1601,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
[[package]]
+name = "pinyin"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e225f595052d9c46045755be4b8d7950b6d9f3c33e0c0b74ba58f11bbfa8c64b"
+
+[[package]]
name = "pipewire"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index f74c26a..bb101a2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,6 +12,7 @@ path = "src/main.rs"
clap = { version = "4.6.1", features = ["derive"] }
tokio = { version = "1.52.3", features = ["net", "rt", "rt-multi-thread", "macros"] }
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
+pinyin = "0.11.0"
[dependencies.vtx-engine]
git = "https://github.com/Weicao-CatilGrass/vtx-engine"
diff --git a/help.txt b/help.txt
index d4aff6e..649cb67 100644
--- a/help.txt
+++ b/help.txt
@@ -6,6 +6,7 @@ Options
stdout | stderr | tcp | udp | udp-broadcast | ipc
-m, --model=<model> Whisper model. [default: base_en]
--lang=<code> Language hint (zh, ja, en, fr...). Skips detection.
+ --pinyin Convert Chinese output to pinyin format.
-f, --format=<pattern> Output format with %{vol}, %{word}, %{confid}.
[default: %{vol},%{word}]
-S, --format-file=<path> Read format from file.
diff --git a/src/args.rs b/src/args.rs
index 679d8e1..11a1f11 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -117,6 +117,10 @@ pub struct DMVOPArguments {
require_equals = true
)]
pub subnet_mask: String,
+
+ // Convert text output to pinyin (Chinese romanization)
+ #[arg(long = "pinyin")]
+ pub use_pinyin: bool,
}
#[derive(Clone, Debug)]
@@ -178,6 +182,16 @@ pub fn format_output(pattern: &str, word: &str, confidence: f32, volume: f32) ->
result
}
+/// Convert transcribed text to pinyin if the `use_pinyin` flag is set.
+/// Otherwise returns the original text as a String.
+pub fn maybe_to_pinyin(text: &str, use_pinyin: bool) -> String {
+ if use_pinyin {
+ pinyin::to_pinyin_vec(text, pinyin::Pinyin::plain).join(" ")
+ } else {
+ text.to_string()
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/main.rs b/src/main.rs
index fabf16c..e3a5b84 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -31,7 +31,7 @@ impl OutputChannel {
}
}
- async fn send(&self, message: &str) {
+ async fn send_to_channel(&self, message: &str) {
match self {
OutputChannel::Stdout(p) => p.clone().send(message).await,
OutputChannel::Stderr(p) => p.clone().send(message).await,
@@ -252,17 +252,19 @@ async fn main() {
match rx.recv().await {
Ok(event) => match event {
vtx_engine::EngineEvent::TranscriptionComplete(result) => {
- let formatted = format_output(&pattern, &result.text, 0.0, last_volume_db);
+ let raw = maybe_to_pinyin(&result.text, args.use_pinyin);
+ let formatted = format_output(&pattern, &raw, 0.0, last_volume_db);
for ch in &channels {
- ch.send(&formatted).await;
+ ch.send_to_channel(&formatted).await;
}
}
vtx_engine::EngineEvent::TranscriptionSegment(segment) => {
- let formatted = format_output(&pattern, &segment.text, 0.0, last_volume_db);
+ let raw = maybe_to_pinyin(&segment.text, args.use_pinyin);
+ let formatted = format_output(&pattern, &raw, 0.0, last_volume_db);
for ch in &channels {
- ch.send(&formatted).await;
+ ch.send_to_channel(&formatted).await;
}
}
vtx_engine::EngineEvent::VisualizationData(viz) => {