how to convert byte array or binary data into audio file - iphone

I need help in my iphone application, I want to convert byte array or binary data into audio file.Please help me out and tell me any way so i con do it.

If your array is supposed to contain audio data in PCM format, than you can simply add WAVE header at the beginning to get ready to play audio file. Format of header is described here.

Related

Convert byte[] to Video (mp4 or any other palyable format)

I am creating a bot that will record the Microsoft team live sessions. Audio recording is working fine but facing problems in generating the video file. The process I am following is that I am converting the video data into a byte array and then writing the data to a video format file.
I am adding some code snippets, I have examined so far.
1. Stream videoStream = new FileStream(videoFilePath, FileMode.Create);
BinaryWriter videoStreamWriter = new BinaryWriter(videoStream);
videoStreamWriter.Write(videoBytesArray, 0, videoBytesArray.Length);
videoStreamWriter.Close();
2. System.IO.File.WriteAllBytes(videoFilePath, videoBytesArray);
The generated files from the above code snippets are of an unsupported format.
It may be because of the data receiving from the session.
I am receiving the data through the Local media session's Video Socket on VideoMediaReceived Event (ICall.ILocalMediaSession.VideoSockets). The Video Color Format of the data that the socket is receiving is of H264 Format.
A similar problem I encountered when creating the audio file. For that, I utilized the WaveFormat package for creating an audio file.
So, Is there any library/method to convert the byte array to a video file of any format?
#Murtaza, you can try this and see if it helps. If the byte array is already a video stream then, simply you can serialize it to the disk with the extension mp4. (If it's an MP4 encoded stream).
Stream t = new FileStream("video.mp4", FileMode.Create);
BinaryWriter b = new BinaryWriter(t);
b.Write(videoData);
t.Close();

mp4v2 extracting and decoding data from .M4A file

I have extracted the audio data from .m4a file using mp4v2 library (sample-by-sample). Does this library have function that decodes the data? Anybody with experience with this library and can provide some help?
The documentation says:
MP4ReadSample function reads the specified sample from the specified track.
Typically this sample is then decoded in a codec dependent fashion and
rendered in an appropriate fashion.
I am interesed in decoding the output.
Thanks in advance.
You tagged MP4(video data) and M4A(audio data). Since you are extracting from M4A, I can only imagine you actually have either AAC or MP3 audio data.
Each extracted sample (bytes) is audio frame.
To make a playable MP3 file : Simply join all MP3 frames' bytes together. Save as .mp3 to play later.
To make a playable AAC file : For each AAC frame, first create an ADTS header (7 bytes) followed by that frame's data. You can test your header bytes here (site shows what your byte values mean). When all your AAC frames each begin with an ADTS header, simply save as .aac to play later using some audio payer code.
I have researched everything and the answer is NO. There is no decoder in mp4/mp4v2 libraries. One has to use some other library to do that.

How to create an Mp4 file from H264 raw data that I am receiving from a live streamer

How to create an Mp4 file from H264 raw data that I am receiving from a live streamer (no predefined duration or moov atom), unfortunately can't use FFMPEG, I have to write my own code using live555. Can somebody help me with Mp4 container and how h264 data has to be pushed into it.? Thank you in advance : )
There are several operations to be made to store H.264 raw data into MP4, among them:
create box structures, in particular the moov box
store the NAL units in a mdatbox, possibly storing non-VCL NAL units in the moovbox
replace start codes with length fields
It also depends on your requirements. If you want to do the conversion on-the-fly, you have to use fragmented mp4. If you can store the H264 and then do the conversion, you may use non-fragmented mp4. In particular using MP4Box:
MP4Box -add file.264 file.mp4

how can i play pcm with AVPlayer

I'm using AVPlayer to play local .mp3 file and audio stream from server.
And i want to play local .pcm file too.
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory
, NSUserDomainMask
, YES);
NSString * voiceFile = [[paths objectAtIndex:0] stringByAppendingPathComponent:#"OutPut.pcm"];
But it didn't work. i got unknown error.
It seems AudioQueue can play .pcm correctly.
But is there a sample way can let AVPlayer direct play .pcm just like .mp3?
Neither .pcm as a file extension or PCM data specifies a readable format. The player cannot recognize an arbitrary data stream. It is certainly capable of reading file formats which contain PCM data, but this PCM representation is missing several things typical audio file formats represent:
Sample Rate
Sample Size
Sample Format
Channel Count
and so on.
You should instead save that PCM data in an audio file format the player supports (e.g. a WAV file).
If you prefer to simply stream PCM audio information and you know the stream format, you can approach that problem using an AudioQueue.

Encode audio from iphone mic into gsm

I'm using monotouch to create iphone applications and I need to encode audio that I receive from the mic into a gsm file.
I have already encoded audio into wav, but now, for more specific needs, I need to record it into GSM. If someone could tell me or show me some doc that explains either how to encode from mic into gsm or how to convert wav into gsm that would be awesome.
Ty,
Axel
--- UPDATE ---
There's an entry for MicrosoftGSM in MonoTouch.AudioToolbox.AudioFormatType, yet I get a 1718449215 OSStatus error. I guess that the reason is that my other arguments aren't corrent. Tough I don't know the specification for saving as GSM. Here's my not working code:
//set up the NSObject Array of values that will be combined with the keys to make the NSDictionary
NSObject[] values = new NSObject[]
{
NSNumber.FromFloat (44100.0f), //Sample Rate
NSNumber.FromInt32 ((int)MonoTouch.AudioToolbox.AudioFormatType.MicrosoftGSM),
NSNumber.FromInt32(2),
NSNumber.FromInt32((int)AVAudioQuality.High),
};
//Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary
NSObject[] keys = new NSObject[]
{
AVAudioSettings.AVSampleRateKey,
AVAudioSettings.AVFormatIDKey,
AVAudioSettings.AVNumberOfChannelsKey,
AVAudioSettings.AVEncoderAudioQualityKey,
};
//Set Settings with the Values and Keys to create the NSDictionary
settings = NSDictionary.FromObjectsAndKeys (values, keys);
Bad news, there is no built in way to use AVAudioRecorder to record GSM audio files
The only supported audio recording formats are
MPEG4AAC
AppleLossless
AppleIMA4
iLBC
ULaw
LinearPCM
Anyways you could setup a webservice and use a third party converter like SoX that can convert the audio for you.
btw if you try to use the recorder using MicrosoftGSM format you will likely to get an OSStatus error 1718449215 which is the representation of kAudioFormatUnsupportedDataFormatError error
Alex