|
1 | 1 | use std::path::PathBuf;
|
| 2 | +use std::process::{Command, Stdio}; |
| 3 | + |
| 4 | +use orfail::OrFail; |
2 | 5 |
|
3 | 6 | use crate::json::JsonObject;
|
| 7 | +use crate::media::MediaStreamId; |
4 | 8 |
|
5 | 9 | #[derive(Debug, Clone)]
|
6 |
| -pub struct SourceAudioSinkPluginSpec { |
| 10 | +pub struct SpeechToTextPluginSpec { |
7 | 11 | pub command: PathBuf,
|
8 | 12 | pub args: Vec<String>,
|
| 13 | + pub output_file: PathBuf, |
9 | 14 | }
|
10 | 15 |
|
11 |
| -impl<'text, 'raw> TryFrom<nojson::RawJsonValue<'text, 'raw>> for SourceAudioSinkPluginSpec { |
| 16 | +impl<'text, 'raw> TryFrom<nojson::RawJsonValue<'text, 'raw>> for SpeechToTextPluginSpec { |
12 | 17 | type Error = nojson::JsonParseError;
|
13 | 18 |
|
14 | 19 | fn try_from(value: nojson::RawJsonValue<'text, 'raw>) -> Result<Self, Self::Error> {
|
15 | 20 | let obj = JsonObject::new(value)?;
|
16 | 21 | Ok(Self {
|
17 | 22 | command: obj.get_required("command")?,
|
18 | 23 | args: obj.get("args")?.unwrap_or_default(),
|
| 24 | + output_file: obj.get_required("output_file")?, |
19 | 25 | })
|
20 | 26 | }
|
21 | 27 | }
|
22 | 28 |
|
23 | 29 | #[derive(Debug)]
|
24 |
| -pub struct SourceAudioSinkPlugin { |
| 30 | +pub struct SpeechToTextPlugin { |
25 | 31 | 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 | + } |
26 | 58 | }
|
0 commit comments