naudio

How can I play byte array of audio raw data using NAudio?

为君一笑 提交于 2019-12-29 01:35:24
问题 byte[] bytes = new byte[1024]; Assume bytes is an array filled with audio raw data. How can I play this byte array using a WaveOut object? _waveOut.Init(bytes); // <- Error: cannot resolve method. _waveOut.Play(); 回答1: I figured it out, here is the solution: byte[] bytes = new byte[1024]; IWaveProvider provider = new RawSourceWaveStream( new MemoryStream(bytes), new WaveFormat()); _waveOut.Init(provider); _waveOut.Play(); 回答2: The accepted answer assumes the byte stream is 44,1kHz, 16 bit,

Receiving “Not a WAVE file - no RIFF header” when creating wave stream from mp3 conversion stream

和自甴很熟 提交于 2019-12-25 13:31:11
问题 I'm trying to convert a mp3 into a wave stream using NAudio. Unfortunately I receive the error Not a WAVE file - no RIFF header on the third line when creating the wave reader. var mp3Reader = new Mp3FileReader(mp3FileLocation); var pcmStream = WaveFormatConversionStream.CreatePcmStream(mp3Reader); var waveReader = new WaveFileReader(pcmStream) Shouldn't these streams work together properly? My goal is to combine several mp3s and wavs into a single stream for both playing and saving to disc(

Double array to wav

北城以北 提交于 2019-12-25 10:01:24
问题 I want to export a double[] array to a wav file. I'm having some trouble manipulating the headers (RIFF, fmt, etc) . Any ideas how I should approach this? Maybe use BitConverter to turn the double[] array into a byte[] array and then use NAudio's waveFileWriter? Any sample code much appreciated! 回答1: Just use WaveFileWriter's WriteSample method to write each sample one by one, or WriteSamples to do it in one hit. Since you have an array of doubles, you can use a bit of LINQ to convert to a

How to store a .wav file in Windows 10 with NAudio

情到浓时终转凉″ 提交于 2019-12-25 09:04:48
问题 I'm trying to store my 16000hz 16bit mono PCM audio bytes to a wav file in a Windows 10 app. NAudio normaly has a WavFileWriter, but it seems to be gone in the Windows 10 version. I can only seem to find access to new WaveFormat(16000, 16, 1); from https://www.nuget.org/packages/NAudio/1.7.3/ Is there a stream I can use to create the Wav file or its bytes? 回答1: I suspect that NAudio removed WavFileWriter because there's now a substitute in the standard UWP API, in the Windows.Media.Audio

C# NAudio rendering a waveform ASP.net without DMO or ACM

一笑奈何 提交于 2019-12-25 07:28:48
问题 I'm trying to draw out a waveform using ASP.net on an Azure Website (which doesn't have the ACM or DMO codecs installed), so I had to use NLayer to read the mp3 file. The code I have below works perfectly with the regular DmoMp3FrameDecompressor, but when I use the NLayer decompressor it doesn't. Maybe the format of the NLayer decompressor is 32bit Float and not 16bit PCM. byte[] data = new WebClient().DownloadData(URL); int maxAmplitude = 0; short[,] dataArray = new short[Width, 2]; //using

NAudio AsioOut + Sockets

烂漫一生 提交于 2019-12-25 06:59:52
问题 I'm newbie in audio programming and in sockets programming. I'm trying to send guitar signal over a network using NAudio AsioOut class and Sockets. Here's source code of Receiver and Sender. It seems like the receiver really gets the bytes array from sender, but all what I hear is white noise. Receiver source code using System; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; using NAudio.Utils; using NAudio.Wave; using NAudio.Wave

Decoding GSM 6.10 parts in NAudio

感情迁移 提交于 2019-12-25 06:55:46
问题 How can I decode GSM 6.10 (Full-Rate) codec audio byte array on the fly in NAudio? Sources says that wave decoding is processed at one time and I can't process several bytes of wave (fix me if I'm wrong). My situation is that I receive bytes array of GSM 6.10 audio from the server, array size can be specified, but how can i decode it and write to the device? Edit: What am I doing wrong? According to Mark's solution this should work but all I hear is distorted sounds: WaveOut waveO = new

How to decode mp3 to wav on Azure WebApp

二次信任 提交于 2019-12-25 06:25:26
问题 I have a problem with decoding mp3 to wav (or byte array, or pcm stream) using NAudio when my asp.net mvc5 application running on Azure. On the local IIS it works properly. But on the Azure I'm getting "System.Runtime.InteropServices.COMException" when calling Mp3FileReader. I think it may be cause of missing codecs. How can I solve this problem? Is there a way to make a reference or something? Thanks in advance! 回答1: if you are using Azure App Service, most likely some of the call would be

Reading Mp3 File using NAudio.dll on windows server 2008 r2 when media player is not installed

荒凉一梦 提交于 2019-12-25 04:17:10
问题 I am reading the length of mp3 files using NAdutio.dll. the code sample i used is here. the application i have created is a stand alone desktop application built in C# 4.0 and is used on the network of computers all with windows server 2008 operating systems. and there is no media player installed on any of those computer. when i run the application on my local machine it return the length of mp3 files correctly, but when it is run on any pc on that network it return zero for every file. it

NAudio change volume in runtime

旧巷老猫 提交于 2019-12-25 03:59:10
问题 I would like change the volume of my audiostream in runtime. I use this code: Public Volume as Single = 0.01 Dim Wave1 As New NAudio.Wave.WaveOut Dim xa() As Byte = IO.File.ReadAllBytes("C:\Song - Come Out and Play.wav") Sub PlaySound() Dim data As New IO.MemoryStream(xa) Wave1.Init(New NAudio.Wave.BlockAlignReductionStream(NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(New NAudio.Wave.WaveFileReader(data)))) Wave1.Volume = Volume Wave1.Play() End Sub Private Sub Form1_Load(ByVal