【7Focus】
【7Focus】
Explore posts from servers
CC#
Created by 【7Focus】 on 1/19/2024 in #help
record microphone
hello. I am trying to record my own microphone. I am currently using the NAudio lib. my problem is that everytime I start recording the record stops after 1 second and doesnt record anything. this is my code:
c#
public class Recorder
{
private WaveInEvent waveSource = null;
private WaveFileWriter waveFile = null;

public void StartRecording()
{
waveSource = new WaveInEvent();
waveSource.WaveFormat = new WaveFormat(44100, 1);

waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
waveSource.RecordingStopped += new EventHandler<StoppedEventArgs>(waveSource_RecordingStopped);

waveFile = new WaveFileWriter(@"D:\Downloads\test\testfile.wav", waveSource.WaveFormat);

waveSource.StartRecording();
}

public void StopRecording()
{
if (waveSource != null)
{
waveSource.StopRecording();
waveSource.Dispose();
waveSource = null;
}

if (waveFile != null)
{
waveFile.Dispose();
waveFile = null;
}
}

private void waveSource_DataAvailable(object sender, WaveInEventArgs e)
{
if (waveFile != null)
{
waveFile.Write(e.Buffer, 0, e.BytesRecorded);
waveFile.Flush();
}
}

private void waveSource_RecordingStopped(object sender, StoppedEventArgs e)
{
if (waveSource != null)
{
waveSource.Dispose();
waveSource = null;
}

if (waveFile != null)
{
waveFile.Dispose();
waveFile = null;
}
}
}
c#
public class Recorder
{
private WaveInEvent waveSource = null;
private WaveFileWriter waveFile = null;

public void StartRecording()
{
waveSource = new WaveInEvent();
waveSource.WaveFormat = new WaveFormat(44100, 1);

waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
waveSource.RecordingStopped += new EventHandler<StoppedEventArgs>(waveSource_RecordingStopped);

waveFile = new WaveFileWriter(@"D:\Downloads\test\testfile.wav", waveSource.WaveFormat);

waveSource.StartRecording();
}

public void StopRecording()
{
if (waveSource != null)
{
waveSource.StopRecording();
waveSource.Dispose();
waveSource = null;
}

if (waveFile != null)
{
waveFile.Dispose();
waveFile = null;
}
}

private void waveSource_DataAvailable(object sender, WaveInEventArgs e)
{
if (waveFile != null)
{
waveFile.Write(e.Buffer, 0, e.BytesRecorded);
waveFile.Flush();
}
}

private void waveSource_RecordingStopped(object sender, StoppedEventArgs e)
{
if (waveSource != null)
{
waveSource.Dispose();
waveSource = null;
}

if (waveFile != null)
{
waveFile.Dispose();
waveFile = null;
}
}
}
1 replies
CC#
Created by 【7Focus】 on 10/14/2023 in #help
✅ Failing to start custom background service
Hello there. Does anyone know how I can auto start my background worker service when my pc starts? I was able to create a service but when I run it from "Services" it crashes (Error: 1053). I appreciate every help.
6 replies
CC#
Created by 【7Focus】 on 10/1/2023 in #help
❔ putting my app in foreground without making other apps lose focus
I am making a checklist app and I want it to be shown above all other apps. the problem is that if I am using a fullscreen app and want to interact with my checklist app the other app loses focus and minimizes. how can I prevent that?
32 replies
CC#
Created by 【7Focus】 on 9/29/2023 in #help
❔ rendering windows forms over another window
hello : ) my goal is to make a checklist application that can be rendered over other windows so you the other window does not loose focus in c#. can you give me some advice on how I should execute/render my forms so they are rendered over a different window so you can click buttons and press key in the window of your choice and my own form gui at the same time?
26 replies