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);
|
File.Delete(WavPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.LogDebug("Starting ffmpeg to record audio...");
|
Logger.LogDebug("Starting pw-record to record audio...");
|
||||||
|
|
||||||
var pInfo = new ProcessStartInfo
|
var pInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = "ffmpeg",
|
FileName = "pw-record",
|
||||||
Arguments = $"-f alsa -i default -y {WavPath}",
|
Arguments = $"--rate=16000 --channels=1 --format=s16 \"{WavPath}\"",
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
CreateNoWindow = true,
|
CreateNoWindow = true,
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
@@ -50,17 +50,22 @@ public static class AudioRecorder
|
|||||||
var process = Process.GetProcessById(pid.Value);
|
var process = Process.GetProcessById(pid.Value);
|
||||||
if (!process.HasExited)
|
if (!process.HasExited)
|
||||||
{
|
{
|
||||||
// Send gracefully? Process.Kill on linux sends SIGKILL by default.
|
// Gracefully stop pw-record using SIGINT to ensure WAV headers are finalizing cleanly
|
||||||
// But ffmpeg can sometimes handle SIGINT or SIGTERM if we use alternative tools or Process.Kill.
|
Process.Start(new ProcessStartInfo
|
||||||
// Standard .NET Process.Kill(true) kills the tree. Let's start with basic Kill.
|
{
|
||||||
process.Kill();
|
FileName = "kill",
|
||||||
process.WaitForExit();
|
Arguments = $"-INT {pid.Value}",
|
||||||
|
CreateNoWindow = true,
|
||||||
|
UseShellExecute = false
|
||||||
|
})?.WaitForExit();
|
||||||
|
|
||||||
|
process.WaitForExit(2000); // give it a moment to flush
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Process might already be dead
|
// Process might already be dead
|
||||||
Console.WriteLine($"[AudioRecorder] Error stopping ffmpeg: {ex.Message}");
|
Console.WriteLine($"[AudioRecorder] Error stopping pw-record: {ex.Message}");
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ Built with **.NET 10** and compiled to **Native AOT**, Toak runs as a lightning-
|
|||||||
## 🛠 Prerequisites
|
## 🛠 Prerequisites
|
||||||
|
|
||||||
- **.NET 10 SDK** (for building from source)
|
- **.NET 10 SDK** (for building from source)
|
||||||
- **ffmpeg** (for audio capture processing)
|
- **pipewire** / **pw-record** (for native Wayland/Linux audio capture)
|
||||||
- **Typing Backend**: `wtype` (Wayland) or `xdotool` (X11)
|
- **Typing Backend**: `wtype` (Wayland) or `xdotool` (X11)
|
||||||
- **Groq API Key**: Get one at [console.groq.com](https://console.groq.com/)
|
- **Groq API Key**: Get one at [console.groq.com](https://console.groq.com/)
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ Toak/
|
|||||||
│ └── Models/ # API payload representations
|
│ └── Models/ # API payload representations
|
||||||
├── Assets/ # Sound files or other static resources
|
├── Assets/ # Sound files or other static resources
|
||||||
├── Audio/
|
├── Audio/
|
||||||
│ └── AudioRecorder.cs # Handles audio capture via system utilities (e.g., ffmpeg/arecord)
|
│ └── AudioRecorder.cs # Handles audio capture via system utilities (e.g., pw-record from PipeWire)
|
||||||
├── Commands/
|
├── Commands/
|
||||||
│ ├── ToggleCommand.cs # Start/stop recording and pass pipe/copy flags
|
│ ├── ToggleCommand.cs # Start/stop recording and pass pipe/copy flags
|
||||||
│ ├── DiscardCommand.cs # Abort the current recording
|
│ ├── DiscardCommand.cs # Abort the current recording
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ set -e
|
|||||||
echo "Building Toak Native AOT executable..."
|
echo "Building Toak Native AOT executable..."
|
||||||
dotnet publish -c Release -r linux-x64
|
dotnet publish -c Release -r linux-x64
|
||||||
|
|
||||||
|
systemctl --user stop toak.service
|
||||||
|
systemctl --user disable toak.service
|
||||||
echo "Installing to /usr/bin/toak... (This may prompt for your sudo password)"
|
echo "Installing to /usr/bin/toak... (This may prompt for your sudo password)"
|
||||||
sudo cp bin/Release/net10.0/linux-x64/publish/Toak /usr/bin/toak
|
sudo cp bin/Release/net10.0/linux-x64/publish/Toak /usr/bin/toak
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user