Skip to content

Commit 2392ff0

Browse files
committed
feat: プラグイン名をSourceAudioSinkからSpeechToTextに変更し、起動処理を追加
1 parent ad39e3d commit 2392ff0

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

src/plugin.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,58 @@
11
use std::path::PathBuf;
2+
use std::process::{Command, Stdio};
3+
4+
use orfail::OrFail;
25

36
use crate::json::JsonObject;
7+
use crate::media::MediaStreamId;
48

59
#[derive(Debug, Clone)]
6-
pub struct SourceAudioSinkPluginSpec {
10+
pub struct SpeechToTextPluginSpec {
711
pub command: PathBuf,
812
pub args: Vec<String>,
13+
pub output_file: PathBuf,
914
}
1015

11-
impl<'text, 'raw> TryFrom<nojson::RawJsonValue<'text, 'raw>> for SourceAudioSinkPluginSpec {
16+
impl<'text, 'raw> TryFrom<nojson::RawJsonValue<'text, 'raw>> for SpeechToTextPluginSpec {
1217
type Error = nojson::JsonParseError;
1318

1419
fn try_from(value: nojson::RawJsonValue<'text, 'raw>) -> Result<Self, Self::Error> {
1520
let obj = JsonObject::new(value)?;
1621
Ok(Self {
1722
command: obj.get_required("command")?,
1823
args: obj.get("args")?.unwrap_or_default(),
24+
output_file: obj.get_required("output_file")?,
1925
})
2026
}
2127
}
2228

2329
#[derive(Debug)]
24-
pub struct SourceAudioSinkPlugin {
30+
pub struct SpeechToTextPlugin {
2531
pub process: std::process::Child,
32+
pub input_stream_ids: Vec<MediaStreamId>,
33+
}
34+
35+
impl SpeechToTextPlugin {
36+
pub fn start(
37+
input_stream_ids: Vec<MediaStreamId>,
38+
spec: &SpeechToTextPluginSpec,
39+
) -> orfail::Result<Self> {
40+
let process = Command::new(&spec.command)
41+
.args(&spec.args)
42+
.stdin(Stdio::piped())
43+
.stdout(Stdio::piped())
44+
.stderr(Stdio::inherit())
45+
.spawn()
46+
.or_fail_with(|e| {
47+
format!(
48+
"failed to start speech-to-text plugin command '{}': {e}",
49+
spec.command.display()
50+
)
51+
})?;
52+
53+
Ok(Self {
54+
process,
55+
input_stream_ids,
56+
})
57+
}
2658
}

0 commit comments

Comments
 (0)