feat: Replace ffmpeg with pw-record for audio capture and add service stop/disable to the install script.
This commit is contained in:
@@ -19,12 +19,12 @@ public static class AudioRecorder
|
||||
File.Delete(WavPath);
|
||||
}
|
||||
|
||||
Logger.LogDebug("Starting ffmpeg to record audio...");
|
||||
Logger.LogDebug("Starting pw-record to record audio...");
|
||||
|
||||
var pInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "ffmpeg",
|
||||
Arguments = $"-f alsa -i default -y {WavPath}",
|
||||
FileName = "pw-record",
|
||||
Arguments = $"--rate=16000 --channels=1 --format=s16 \"{WavPath}\"",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardOutput = true,
|
||||
@@ -50,17 +50,22 @@ public static class AudioRecorder
|
||||
var process = Process.GetProcessById(pid.Value);
|
||||
if (!process.HasExited)
|
||||
{
|
||||
// Send gracefully? Process.Kill on linux sends SIGKILL by default.
|
||||
// But ffmpeg can sometimes handle SIGINT or SIGTERM if we use alternative tools or Process.Kill.
|
||||
// Standard .NET Process.Kill(true) kills the tree. Let's start with basic Kill.
|
||||
process.Kill();
|
||||
process.WaitForExit();
|
||||
// Gracefully stop pw-record using SIGINT to ensure WAV headers are finalizing cleanly
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "kill",
|
||||
Arguments = $"-INT {pid.Value}",
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false
|
||||
})?.WaitForExit();
|
||||
|
||||
process.WaitForExit(2000); // give it a moment to flush
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Process might already be dead
|
||||
Console.WriteLine($"[AudioRecorder] Error stopping ffmpeg: {ex.Message}");
|
||||
Console.WriteLine($"[AudioRecorder] Error stopping pw-record: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user