|
发表于 2023-10-19 15:46:11
|
显示全部楼层
广西壮族自治区南宁市
using System;
using System.Diagnostics;
using NAudio.Wave;
class Program
{
static void Main()
{
// 获取要录制的进程ID
int processId = GetProcessIdByName("YourProcessName");
// 初始化WaveInEvent和WaveFileWriter
WaveInEvent waveIn = new WaveInEvent();
string outputFilePath = "output.wav";
WaveFileWriter writer = new WaveFileWriter(outputFilePath, waveIn.WaveFormat);
// 设置录制回调函数
waveIn.DataAvailable += (sender, e) =>
{
writer.Write(e.Buffer, 0, e.BytesRecorded);
};
// 开始录制
waveIn.StartRecording();
Console.WriteLine("Recording... Press any key to stop.");
Console.ReadKey();
// 停止录制
waveIn.StopRecording();
writer.Close();
Console.WriteLine($"Recording saved to {outputFilePath}");
}
// 根据进程名称获取进程ID
static int GetProcessIdByName(string processName)
{
Process[] processes = Process.GetProcessesByName(processName);
if (processes.Length > 0)
{
return processes[0].Id;
}
else
{
throw new ArgumentException($"Could not find process with name: {processName}");
}
}
}
Csahrp代码。调用了Naudio库 |
评分
-
参与人数 1 | 荣誉 +1 |
收起
理由
|
笨潴
| + 1 |
热心帮助他人,荣誉+1,希望继续努力(*^__^*) 嘻嘻! |
查看全部评分
|