public static bool TakeClipAddSilence(string file, TimeSpan lengthSilence, TimeSpan startTime, TimeSpan length, string newFile) { try { //byte[] buffer = new byte[1024]; AudioFileReader afr = new AudioFileReader(file); OffsetSampleProvider offsetter = new OffsetSampleProvider(afr) { DelayBy = lengthSilence, LeadOut = lengthSilence, SkipOver = startTime, Take = length }; offsetter.ToMono(); var provider = new SampleToWaveProvider(offsetter); WaveFileWriter.CreateWaveFile(newFile, provider); ChangeWaveFormat(newFile, 16000, 16, 1); return(true); } catch (Exception exc) { ErrorMessage.Raise(exc); return(false); } }
public void wasapiPlay() { ISampleProvider sampleProvider1; VolumeSampleProvider volumeSampleProv1; SmbPitchShiftingSampleProvider smbPitchSampleProv1; OffsetSampleProvider offsetSampleProv1; PanningSampleProvider panSampleProv1; void funcForBuff(object sender, WaveInEventArgs waveInEventArgs) { buffWaveProv.AddSamples(waveInEventArgs.Buffer, 0, waveInEventArgs.BytesRecorded); } var enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator(); wInput = enumerator.GetDevice(strInputDeviceID); wOutput = enumerator.GetDevice(strOutputDeviceID); wOut = new WasapiOut(wOutput, AudioClientShareMode.Shared, true, 10); wCapture = new WasapiCapture(wInput, true, 10); buffWaveProv = new BufferedWaveProvider(wCapture.WaveFormat); wCapture.DataAvailable += funcForBuff; sampleProvider1 = buffWaveProv.ToSampleProvider(); smbPitchSampleProv1 = new SmbPitchShiftingSampleProvider(sampleProvider1); smbPitchSampleProv1.PitchFactor = fPitch; offsetSampleProv1 = new OffsetSampleProvider(smbPitchSampleProv1); offsetSampleProv1.DelayBy = new TimeSpan(0, 0, 0, 0, iLatency); panSampleProv1 = new PanningSampleProvider(offsetSampleProv1.ToMono(1f, 1f)); panSampleProv1.Pan = fPanning; volumeSampleProv1 = new VolumeSampleProvider(panSampleProv1); volumeSampleProv1.Volume = fVolume; wOut.Init(volumeSampleProv1); wCapture.StartRecording(); wOut.Play(); }
private static ISampleProvider GetProvider(ISampleProvider source, TimeSpan take, TimeSpan fadeIn, TimeSpan fadeOut, TimeSpan skip, float volume) { var offset = new OffsetSampleProvider(source) { SkipOver = skip, Take = take }; var mono = offset.ToMono(volume, volume); if (fadeIn == TimeSpan.Zero && fadeOut == TimeSpan.Zero) { return(mono); } var fade = new TimedFadeInOutSampleProvider(mono, fadeIn != TimeSpan.Zero); if (fadeIn != TimeSpan.Zero) { fade.AddFadeIn(TimeSpan.Zero, fadeIn); } if (fadeOut != TimeSpan.Zero) { fade.AddFadeOut(take - fadeOut, fadeOut); } return(fade); }