I am facing the following problem regarding to the voice (Audio) recording in windows phone 7.
I am recording the sound using Microphone class available in Microsoft.Xna.Framework.Audio namespace. here is the code -
Variable declaration:
private Microphone mic = Microphone.Default;
private MemoryStream stream;
private const string FILE_NAME = "recording.mp3";
byte[] buffer;
Recording Button click code-
mic.BufferDuration = TimeSpan.FromSeconds(1);
buffer = new byte[mic.GetSampleSizeInBytes(mic.BufferDuration)];
// Create the event handler. I could have done an anonymous
// delegate here if I had so desired.
mic.BufferReady += new EventHandler<EventArgs>(mic_BufferReady);
stream = new MemoryStream();
mic.Start();
Buffer Ready Event code ----------
void mic_BufferReady(object sender, EventArgs e)
{
mic.GetData(buffer);
// Write buffer to stream
stream.Write(buffer, 0, buffer.Length);
}
Button stop code -
private void btnStop_Click(object sender, RoutedEventArgs e)
{
dt.Stop();
btnStop.IsEnabled = false;
btnPlayRecording.IsEnabled = true;
mic.Stop();
//Writing stream into Storage
writeFile(stream);
}
private void writeFile(MemoryStream s, string name)
{
try
{
using (var userStore = IsolatedStorageFile.GetUserStoreForApplication())
{
if (userStore.FileExists(name))
{
userStore.DeleteFile(name);
}
using (var file = userStore.OpenFile(name, FileMode.CreateNew))
{
s.WriteTo(file);
}
}
}
catch (Exception ee)
{
}
}
Once I save the stream into isolated storage and play it back, the volume is very low and the quality is also not good.
So
- Can we amplify the Volume ?
- can we increase the bitrate ?
- Can we do Fadin-Fadout ?
If all these three is not possible in windows phone 7, then is there any third party API available to perform all these operations?
Thanks in advance
Amplification in .NET is not trivial. The best approach I found was to make an external process call to "SoX, the Swiss Army knife of sound processing programs." (http://sox.sourceforge.net/)
I don't have a Windows 7 phone -- so I don't know for sure that SOX runs there.
The format would be SOX -V volume_parameter inputFileName outputFileName for amplification, so:
"sox.exe -v 3.0 myNormalFile.wav myAmpedFile.wav"
would give you an amplification of 300%. Sox also allows for bitrate change... not sure of Fadein/Fadeout.
I don't have anything specifically for Windows 7 phone, but in straight .NET/C# Code: