I want to make a unity3d appllication for ios, and need to record audio.
I found a way to record audio. But the saving audio format is wav. I want a compressed audio format, like ogg/mp3.
And I watch this question too, but it use lame, can I use lame on ios?
I thinks there are 2 ways:
I have no ideas now, hope your help!
I try this lib NAudio.Lame.
But it cannot be used in unity engine, do you know how to make it support unity engine and any platforms for unity? Or other solutions?
Still wait for your help!
There is not only this error, but many other errors too, how to fix it?
No matter
master
orexperimental
branch. One error is Severity Code Description Project File Line Suppression State Error CS0103 The name 'LibMp3Lame' does not exist in the current context NAudio.Lame \C#Projects\NAudio.Lame\MP3FileWriter.cs 636 Active
this is build error in master branch
.
20160416
error CS1061: Type
NAudio.Wave.WaveFileReader' does not contain a definition for
CopyTo' and no extension methodCopyTo' of type
NAudio.Wave.WaveFileReader' could be found (are you missing a using directive or an assembly reference?)
Do you know how to fix it? Or other method to convert to mp3 file instead of the below codes.
using System.IO;
using NAudio.Wave;
using NAudio.Lame;
public static class Codec {
// Convert WAV to MP3 using libmp3lame library
public static void WaveToMP3(string waveFileName, string mp3FileName, int bitRate = 128)
{
using (var reader = new WaveFileReader(waveFileName))
using (var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate))
reader.CopyTo(writer);
}
Get the library on NAudio.Lame and copy one of the dll's in your project. Example code is provided in the source page.
CopyTo method doesn't exist before .NET 4.0. You can write an extension method as in this answer to implement it. Simply copy the code below to somewhere in your project.
public static class StreamExtensions
{
public static void CopyTo(this Stream input, Stream output)
{
byte[] buffer = new byte[16 * 1024]; // Fairly arbitrary size
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, bytesRead);
}
}
}