Ищу способ воспроизвести аудио файл на микрофон как в Soundpad c#
Ищу способ воспроизвести аудио файл на микрофон как в Soundpad
Ответы (1 шт):
Автор решения: Left Mail
→ Ссылка
To play an audio file through the microphone in C#, you can use the WasapiOut class from the NAudio library. Here is an example of how you can use this class to play an audio file through the microphone:
1. Install the NAudio NuGet package.
2. Add the following using statement to your code:
using NAudio.Wave;
3. Use the following code to play an audio file through the microphone:
// Create a new WaveOut object
WaveOut waveOut = new WaveOut();
// Create a new WasapiOut object with the device set to the default microphone
IWavePlayer wavePlayer = new WasapiOut(NAudio.CoreAudioApi.AudioClientShareMode.Shared, 100);
// Create a new AudioFileReader object and set its output to the WaveOut object
AudioFileReader audioFileReader = new AudioFileReader("AudioFile.mp3");
waveOut.Init(audioFileReader);
// Start playing the audio file through the microphone
waveOut.Play();
This code will play the audio file "AudioFile.mp3" through the default microphone. You can use the WasapiOut class to control the volume and mute the audio as well.