From 5eea9f2fef1a840f9c9e6ec6d471fe4f87f1d1fd Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 9 Sep 2026 12:50:56 +0200 Subject: make /grajcuj w\ compress finally work as compressing a file and then /grajcuj'ing Signed-off-by: salmonik --- src/voice/mod.rs | 80 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'src/voice') diff --git a/src/voice/mod.rs b/src/voice/mod.rs index 4087eba..9c92202 100644 --- a/src/voice/mod.rs +++ b/src/voice/mod.rs @@ -188,46 +188,6 @@ pub async fn download_url(client: &reqwest::Client, url: &str) -> Result Ok(bytes.to_vec()) } -/// DEBUG: bypass encode/decode — just pipe through ffmpeg as PCM. -/// If this plays, the streaming pipeline works; bug is in Opus roundtrip. -pub async fn degrade_audio(input: &[u8]) -> Result { - use std::process::Stdio; - - let mut child = tokio::process::Command::new("ffmpeg") - .args([ - "-y", "-i", "pipe:0", "-vn", "-f", "f32le", "-ac", "2", "-ar", "8000", "-b:a", "500", - "pipe:1", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::null()) - .kill_on_drop(true) - .spawn() - .map_err(|e| Error::Custom(format!("ffmpeg passthrough spawn: {e}")))?; - - let mut stdin = child.stdin.take().unwrap(); - let stdout = child - .stdout - .take() - .ok_or_else(|| Error::Custom("stdout not captured".into()))?; - - let owned_input = input.to_vec(); - tokio::spawn(async move { - use tokio::io::AsyncWriteExt; - let _ = stdin.write_all(&owned_input).await; - }); - - let ffmpeg_child = FfmpegChild { - _child: child, - stdout, - }; - - let async_source = AsyncReadOnlySource::new(ffmpeg_child); - let adapter = AsyncAdapterStream::new(Box::new(async_source), 64 * 1024); - let raw = RawAdapter::new(adapter, 48000, 2); - Ok(raw.into()) -} - // ── HTTP streaming via songbird's built-in HttpRequest (legacy) ───── /// Create a songbird `Input` that streams audio directly from an HTTP(S) URL. @@ -268,6 +228,46 @@ impl tokio::io::AsyncRead for FfmpegChild { } } +/// Decode a local audio file via ffmpeg to raw f32 PCM at 48 kHz stereo. +/// No reconnect flags (those are for HTTP streams only). +pub async fn ffmpeg_decode_file(path: &str) -> Result { + use std::process::Stdio; + + let mut child = tokio::process::Command::new("ffmpeg") + .args([ + "-i", + path, + "-vn", + "-f", + "f32le", + "-ar", + "48000", + "-ac", + "2", + "pipe:1", + ]) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .kill_on_drop(true) + .spawn() + .map_err(|e| Error::Custom(format!("ffmpeg decode spawn: {e}")))?; + + let stdout = child + .stdout + .take() + .ok_or_else(|| Error::Custom("ffmpeg stdout not captured".into()))?; + + let ffmpeg_child = FfmpegChild { + _child: child, + stdout, + }; + + let async_source = AsyncReadOnlySource::new(ffmpeg_child); + let adapter = AsyncAdapterStream::new(Box::new(async_source), 64 * 1024); + let raw = RawAdapter::new(adapter, 48000, 2); + Ok(raw.into()) +} + /// Stream an HTTP(S) URL live via an ffmpeg subprocess, producing a songbird /// `Input` of raw f32 PCM at 48 kHz stereo — NO full download. /// -- cgit v1.2.3