简体   繁体   English

Xamarin.Android拆分和串联音频文件

[英]Xamarin.Android splitting and concatenating audio files

I'm currently working on an application which records audio and save the file. 我目前正在开发一个可录制音频并保存文件的应用程序。 Now I'm searching for a solution to split the audio file from a position (for example: split in half and have 2 audio files) and register another audio file. 现在,我正在寻找一种解决方案,以从一个位置拆分音频文件(例如:拆分为两个并包含2个音频文件)并注册另一个音频文件。 In the end I need to concatenate all the audio files (2 or more files) to create one single file. 最后,我需要连接所有音频文件(2个或更多文件)以创建一个文件。 I need to do all this in Xamarin.Android. 我需要在Xamarin.Android中完成所有这些操作。
Did anyone did this sort of things? 有人做过这种事情吗? Is it possible to do this without any library? 是否可以在没有任何库的情况下执行此操作? If not, what library should I use in order to do the cutting and concatenating of the audio files. 如果没有,我应该使用哪个库来进行音频文件的剪切和连接。 I would appreciate any response. 我将不胜感激。

What I have tried is to access the memory stream of the audio file. 我尝试过的是访问音频文件的内存流。 You can access each byte so you know where you wanna cut it. 您可以访问每个字节,以便知道要剪切的位置。

For eg if you are trying to cut a Wav file into 2 files : 例如,如果您尝试将Wav文件切成2个文件:

  1. Specify where you want to cut it (byte[]) 指定要剪切的位置(byte [])
  2. Create a new byte[] beginning with Wav Header (this will be your second 以Wav Header开头创建一个新的byte [](这是您的第二个

     public static void WriteWaveHeader (this Stream stream, int channelCount, int sampleRate, int bitsPerSample) { using (var writer = new BinaryWriter (stream, Encoding.UTF8)) { writer.Seek (0, SeekOrigin.Begin); //chunk ID writer.Write ('R'); writer.Write ('I'); writer.Write ('F'); writer.Write ('F'); writer.Write (-1); // -1 - Unknown size //format writer.Write ('W'); writer.Write ('A'); writer.Write ('V'); writer.Write ('E'); //subchunk 1 ID writer.Write ('f'); writer.Write ('m'); writer.Write ('t'); writer.Write (' '); writer.Write (16); //subchunk 1 (fmt) size writer.Write ((short) 1); //PCM audio format writer.Write ((short) channelCount); writer.Write (sampleRate); writer.Write (sampleRate * 2); writer.Write ((short) 2); //block align writer.Write ((short) bitsPerSample); //subchunk 2 ID writer.Write ('d'); writer.Write ('a'); writer.Write ('t'); writer.Write ('a'); //subchunk 2 (data) size writer.Write (-1); // -1 - Unknown size } } 
    1. Continue this byte[] with your second cut of audio to make a Wav file. 继续第二个音频片段,制作一个Wav文件。

nb : I am using Plugin.AudioRecorder to record the sound and access its stream . nb:我正在使用Plugin.AudioRecorder录制声音并访问其 It also supports real time stream access. 它还支持实时流访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM