initial commit
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<SelfContained>true</SelfContained>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Hush.Audio;
|
||||
|
||||
public class FfmpegAudioRecorder : IAudioRecorder
|
||||
{
|
||||
private Process? _process;
|
||||
|
||||
public bool IsRecording => _process != null && !_process.HasExited;
|
||||
|
||||
public Task StartRecording(string path)
|
||||
{
|
||||
if (IsRecording)
|
||||
throw new InvalidOperationException("Recording is already in progress");
|
||||
|
||||
_process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "ffmpeg",
|
||||
Arguments = $"-f pulse -i default -ac 1 -ar 16000 -f wav \"{path}\" -y",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
}
|
||||
};
|
||||
|
||||
_process.Start();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task StopRecording()
|
||||
{
|
||||
if (_process == null || _process.HasExited)
|
||||
return;
|
||||
|
||||
_process.Kill();
|
||||
await _process.WaitForExitAsync();
|
||||
_process.Dispose();
|
||||
_process = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Hush.Audio;
|
||||
|
||||
public interface IAudioRecorder
|
||||
{
|
||||
Task StartRecording(string path);
|
||||
Task StopRecording();
|
||||
bool IsRecording { get; }
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Hush.Audio;
|
||||
|
||||
public class PipewireAudioRecorder : IAudioRecorder
|
||||
{
|
||||
private Process? _process;
|
||||
private string? _currentPath;
|
||||
|
||||
public bool IsRecording => _process != null && !_process.HasExited;
|
||||
|
||||
public Task StartRecording(string path)
|
||||
{
|
||||
if (IsRecording)
|
||||
throw new InvalidOperationException("Recording is already in progress");
|
||||
|
||||
_currentPath = path;
|
||||
|
||||
_process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "pw-record",
|
||||
Arguments = $"\"{_currentPath}\" --rate=16000 --channels=1",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true
|
||||
}
|
||||
};
|
||||
|
||||
_process.Start();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task StopRecording()
|
||||
{
|
||||
if (!IsRecording || _process == null)
|
||||
return;
|
||||
|
||||
_process.Kill();
|
||||
await _process.WaitForExitAsync();
|
||||
|
||||
_process.Dispose();
|
||||
_process = null;
|
||||
_currentPath = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user