Comments (4)
Can you provide some code? What WAV file are you trying to read? You can copy this file to PC and try opening it with NWaves using demo apps.
Also, I assume, you're trying to open (i.e. read, load) the file - not play it or record it: NWaves does not provide such methods, it's a DSP library.
from nwaves.
it's the second week which I'm trying to just record audio in xamarin
which has an RIFF
header, actully an audio which Nwaves
can work with.
I tried Audio Recorder Plugin and Audio Record and Media Recorder . I asked many questions but got no answer.
the easiest way was Audio Recorder Plugin, but the output hasn't RIFF
header.
the output of Media Recorder was .3gp
which I couldn't convert it to .wav
.
and the output of Media Recorder was .pcm
which also couldn't convert to .wav
here is the last code I tried :
#region Properties
int SAMPLING_RATE_IN_HZ = 44100;
ChannelIn CHANNEL_CONFIG = ChannelIn.Mono;
Android.Media.Encoding AUDIO_FORMAT = Android.Media.Encoding.Pcm16bit;
int BUFFER_SIZE_FACTOR = 2;
int BUFFER_SIZE;
bool RecordingInProgress = false;
private AudioRecord recorder = null;
#endregion
public void Record()
{
BUFFER_SIZE = AudioRecord.GetMinBufferSize(SAMPLING_RATE_IN_HZ,
CHANNEL_CONFIG, AUDIO_FORMAT) * BUFFER_SIZE_FACTOR;
recorder = new AudioRecord(AudioSource.Mic, SAMPLING_RATE_IN_HZ,
CHANNEL_CONFIG, AUDIO_FORMAT, BUFFER_SIZE);
recorder.StartRecording();
RecordingInProgress = true;
RecordingTask();
}
public Task RecordingTask()
{
return Task.Run(() =>
{
string path = "appdir/demo.pcm";
MemoryStream buffer = new MemoryStream(BUFFER_SIZE);
FileOutputStream outStream = new FileOutputStream(path);
var demo2 = RecordingInProgress;
while (RecordingInProgress)
{
int result = recorder.Read(buffer.GetBuffer(), 0, BUFFER_SIZE);
if (result < 0)
{
throw new Exception("Reading of audio buffer failed: ");
}
outStream.Write(buffer.GetBuffer(), 0, BUFFER_SIZE);
}
});
}
public void Stop()
{
if (null == recorder)
{
return;
}
RecordingInProgress = false;
recorder.Stop();
recorder.Release();
recorder = null;
}
}
this code makes a .pcm
file that can't convert to anything with even cloud converters.
I also tried this :
NWaves.Audio.WaveFile waveFile = new NWaves.Audio.WaveFile(buffer.GetBuffer());
waveFile.SaveTo(new FileStream("appdir/demo.wav", FileMode.Create));
insted of outStream.Write(buffer.GetBuffer(), 0, BUFFER_SIZE);
at the bottom of while
closing block
but it says : No RIFF found
there is about 4 or 5 way to record audio. Nwaves can't work with any of them.
the last try I want to do is add RIFF
header to the recorded audio buffer(bytes) programmatically or convert .3gp
or .pcm
to .wav
programmatically.
summary: someone helps me to record an audio in xamarin
which Nwaves can work with.
thanks
-- this is the last question I asked in stackoverflow. I also asked the same question at this link
actually I want to make a voice changer for android.
record audio and change it with Nwaves
.
but the `Nwaves can't work with the recorded audios in android.
from nwaves.
OK, so you just need to read the contents of .pcm
file.
WaveFile
class represents the WAV container, i.e. the PCM data + WAV header. The latter is necessary for correct interpretation of the data in 'pcm' part. And since you know exactly the audio parameters during recording, just read the array of samples from the pcm
file:
// mono mode and Pcm16bit (like in your example):
DiscreteSignal signal;
// sample.pcm is essentially just an array of bytes:
using (var streamIn = new FileStream("sample.pcm", FileMode.Open))
{
var length = (int)streamIn.Length / 2; // divide by 2, because each sample is represented with 2 bytes (Pcm16bit)
signal = new DiscreteSignal(SAMPLING_RATE_IN_HZ, length); // reserve space in the signal for number of samples: length
using (var reader = new BinaryReader(streamIn))
{
for (var i = 0; i < length; i++) // just read samples
{
signal[i] = reader.ReadInt16() / 32768f;
}
}
}
// then you can save it to WAV file, if necessary:
var waveFile = new WaveFile(signal);
using (var stream = new FileStream("sample.wav", FileMode.Create))
{
waveFile.SaveTo(stream);
}
from nwaves.
Thank you Sooooooooo Much ❤
from nwaves.
Related Issues (20)
- Playing saved audio HOT 2
- FeatureExtractor ComputeFrom FastCopy bug HOT 3
- FIR Bandpass Resampling becomes unstable after a long duration HOT 9
- Is there method for series filter? or parallel filter? HOT 2
- How to obtain digital SOS filter from analog zeros and poles? HOT 1
- FFT compatible with OpenAI Whisper features HOT 1
- Help with realtime resampling HOT 3
- Analog poles and zeros of elliptic filter are different from scipy HOT 2
- How to use the polyphase filters implementation
- Buggy RLS filter implementation HOT 3
- how to use stft like scipy.signal "f, t, tf_data = signal.stft(wavedata, fs=fs, window='hamming', nperseg=N_fft, noverlap=int(N_fft*0.8))"? Now we cannot get f,t value. The tf_data is different from var spectrogram = stft.Spectrogram(discreteSignal, normalize: true). HOT 2
- Question: Pitch Patterns
- out of memory using Stft.Spectrogram function HOT 1
- WaveFile: Compiler Warning (level 2) CS0652 @ line 134
- PowerSpectrum and Magnitude spectrum missing from FFT64, RealFFT, RealFFT64
- Order of instruction wrong on wiki page HOT 1
- Pitch shifter produces garbled noise HOT 1
- python speech features fbanks HOT 4
- DiscreteSignal.Samples contain more samples than the original signal HOT 2
- Pitch.FromYin triggers exception for certain sample rates and pitch ranges HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nwaves.