How to convert mp3 to pcm
The mpmediaitem information must be converted to a byte array stream for server upload. So the code below
Reference
async void SoundPickingMedia(object sender, ItemsPickedEventArgs args)
{
if (args.MediaItemCollection.Items != null)
foreach (var item in args.MediaItemCollection.Items)
{
var settings = NSDictionary.FromObjectsAndKeys(new object
{
NSNumber.FromUInt32((int)AudioFormatType.LinearPCM),
NSNumber.FromFloat(44100.0f),
NSNumber.FromUInt32(16),
NSNumber.FromUInt32(2),
NSNumber.FromBoolean(false),
NSNumber.FromBoolean(false),
NSNumber.FromBoolean(false)
},
new object
{
AVAudioSettings.AVFormatIDKey,
AVAudioSettings.AVSampleRateKey,
AVAudioSettings.AVLinearPCMBitDepthKey,
AVAudioSettings.AVNumberOfChannelsKey,
AVAudioSettings.AVLinearPCMIsBigEndianKey,
AVAudioSettings.AVLinearPCMIsFloatKey,
AVAudioSettings.AVLinearPCMBitDepthKey,
});
NSError outError;
byte src;
int size = 0;
using (var asset = new AVUrlAsset(item.AssetURL))
using (var assetReader = new AVAssetReader(asset, out outError))
using (var assetOutput = new AVAssetReaderTrackOutput(asset.Tracks[0], settings))
{
if (outError != null)
return;
if (!assetReader.CanAddOutput(assetOutput))
return;
assetReader.AddOutput(assetOutput);
if (!assetReader.StartReading())
return;
using (var allData = new NSMutableData())
{
while (assetReader.Status != AVAssetReaderStatus.Completed)
{
using (var buffer = assetOutput.CopyNextSampleBuffer())
{
if (buffer == null)
continue;
using (var blockbuffer = buffer.GetDataBuffer())
{
if (blockbuffer == null)
continue;
size = (int)(blockbuffer.DataLength);
if (size <= 0)
continue;
using (var data = NSMutableData.FromLength((nint)size))
{
var err = blockbuffer.CopyDataBytes(0, (uint)size, data.MutableBytes);
if (err != CMBlockBufferError.None)
continue;
allData.AppendData(data);
}
}
}
}
src = allData.ToArray();
}
}
}
}
But the byte array is not played. In my opinion, you need to convert pcm to mp3, etc. xamarin How to convert in c# environment?
In fact, pcm data may work well. If the pcm does not work properly, you should think back to the beginning. T.T.
c# ios xamarin
add a comment |
The mpmediaitem information must be converted to a byte array stream for server upload. So the code below
Reference
async void SoundPickingMedia(object sender, ItemsPickedEventArgs args)
{
if (args.MediaItemCollection.Items != null)
foreach (var item in args.MediaItemCollection.Items)
{
var settings = NSDictionary.FromObjectsAndKeys(new object
{
NSNumber.FromUInt32((int)AudioFormatType.LinearPCM),
NSNumber.FromFloat(44100.0f),
NSNumber.FromUInt32(16),
NSNumber.FromUInt32(2),
NSNumber.FromBoolean(false),
NSNumber.FromBoolean(false),
NSNumber.FromBoolean(false)
},
new object
{
AVAudioSettings.AVFormatIDKey,
AVAudioSettings.AVSampleRateKey,
AVAudioSettings.AVLinearPCMBitDepthKey,
AVAudioSettings.AVNumberOfChannelsKey,
AVAudioSettings.AVLinearPCMIsBigEndianKey,
AVAudioSettings.AVLinearPCMIsFloatKey,
AVAudioSettings.AVLinearPCMBitDepthKey,
});
NSError outError;
byte src;
int size = 0;
using (var asset = new AVUrlAsset(item.AssetURL))
using (var assetReader = new AVAssetReader(asset, out outError))
using (var assetOutput = new AVAssetReaderTrackOutput(asset.Tracks[0], settings))
{
if (outError != null)
return;
if (!assetReader.CanAddOutput(assetOutput))
return;
assetReader.AddOutput(assetOutput);
if (!assetReader.StartReading())
return;
using (var allData = new NSMutableData())
{
while (assetReader.Status != AVAssetReaderStatus.Completed)
{
using (var buffer = assetOutput.CopyNextSampleBuffer())
{
if (buffer == null)
continue;
using (var blockbuffer = buffer.GetDataBuffer())
{
if (blockbuffer == null)
continue;
size = (int)(blockbuffer.DataLength);
if (size <= 0)
continue;
using (var data = NSMutableData.FromLength((nint)size))
{
var err = blockbuffer.CopyDataBytes(0, (uint)size, data.MutableBytes);
if (err != CMBlockBufferError.None)
continue;
allData.AppendData(data);
}
}
}
}
src = allData.ToArray();
}
}
}
}
But the byte array is not played. In my opinion, you need to convert pcm to mp3, etc. xamarin How to convert in c# environment?
In fact, pcm data may work well. If the pcm does not work properly, you should think back to the beginning. T.T.
c# ios xamarin
add a comment |
The mpmediaitem information must be converted to a byte array stream for server upload. So the code below
Reference
async void SoundPickingMedia(object sender, ItemsPickedEventArgs args)
{
if (args.MediaItemCollection.Items != null)
foreach (var item in args.MediaItemCollection.Items)
{
var settings = NSDictionary.FromObjectsAndKeys(new object
{
NSNumber.FromUInt32((int)AudioFormatType.LinearPCM),
NSNumber.FromFloat(44100.0f),
NSNumber.FromUInt32(16),
NSNumber.FromUInt32(2),
NSNumber.FromBoolean(false),
NSNumber.FromBoolean(false),
NSNumber.FromBoolean(false)
},
new object
{
AVAudioSettings.AVFormatIDKey,
AVAudioSettings.AVSampleRateKey,
AVAudioSettings.AVLinearPCMBitDepthKey,
AVAudioSettings.AVNumberOfChannelsKey,
AVAudioSettings.AVLinearPCMIsBigEndianKey,
AVAudioSettings.AVLinearPCMIsFloatKey,
AVAudioSettings.AVLinearPCMBitDepthKey,
});
NSError outError;
byte src;
int size = 0;
using (var asset = new AVUrlAsset(item.AssetURL))
using (var assetReader = new AVAssetReader(asset, out outError))
using (var assetOutput = new AVAssetReaderTrackOutput(asset.Tracks[0], settings))
{
if (outError != null)
return;
if (!assetReader.CanAddOutput(assetOutput))
return;
assetReader.AddOutput(assetOutput);
if (!assetReader.StartReading())
return;
using (var allData = new NSMutableData())
{
while (assetReader.Status != AVAssetReaderStatus.Completed)
{
using (var buffer = assetOutput.CopyNextSampleBuffer())
{
if (buffer == null)
continue;
using (var blockbuffer = buffer.GetDataBuffer())
{
if (blockbuffer == null)
continue;
size = (int)(blockbuffer.DataLength);
if (size <= 0)
continue;
using (var data = NSMutableData.FromLength((nint)size))
{
var err = blockbuffer.CopyDataBytes(0, (uint)size, data.MutableBytes);
if (err != CMBlockBufferError.None)
continue;
allData.AppendData(data);
}
}
}
}
src = allData.ToArray();
}
}
}
}
But the byte array is not played. In my opinion, you need to convert pcm to mp3, etc. xamarin How to convert in c# environment?
In fact, pcm data may work well. If the pcm does not work properly, you should think back to the beginning. T.T.
c# ios xamarin
The mpmediaitem information must be converted to a byte array stream for server upload. So the code below
Reference
async void SoundPickingMedia(object sender, ItemsPickedEventArgs args)
{
if (args.MediaItemCollection.Items != null)
foreach (var item in args.MediaItemCollection.Items)
{
var settings = NSDictionary.FromObjectsAndKeys(new object
{
NSNumber.FromUInt32((int)AudioFormatType.LinearPCM),
NSNumber.FromFloat(44100.0f),
NSNumber.FromUInt32(16),
NSNumber.FromUInt32(2),
NSNumber.FromBoolean(false),
NSNumber.FromBoolean(false),
NSNumber.FromBoolean(false)
},
new object
{
AVAudioSettings.AVFormatIDKey,
AVAudioSettings.AVSampleRateKey,
AVAudioSettings.AVLinearPCMBitDepthKey,
AVAudioSettings.AVNumberOfChannelsKey,
AVAudioSettings.AVLinearPCMIsBigEndianKey,
AVAudioSettings.AVLinearPCMIsFloatKey,
AVAudioSettings.AVLinearPCMBitDepthKey,
});
NSError outError;
byte src;
int size = 0;
using (var asset = new AVUrlAsset(item.AssetURL))
using (var assetReader = new AVAssetReader(asset, out outError))
using (var assetOutput = new AVAssetReaderTrackOutput(asset.Tracks[0], settings))
{
if (outError != null)
return;
if (!assetReader.CanAddOutput(assetOutput))
return;
assetReader.AddOutput(assetOutput);
if (!assetReader.StartReading())
return;
using (var allData = new NSMutableData())
{
while (assetReader.Status != AVAssetReaderStatus.Completed)
{
using (var buffer = assetOutput.CopyNextSampleBuffer())
{
if (buffer == null)
continue;
using (var blockbuffer = buffer.GetDataBuffer())
{
if (blockbuffer == null)
continue;
size = (int)(blockbuffer.DataLength);
if (size <= 0)
continue;
using (var data = NSMutableData.FromLength((nint)size))
{
var err = blockbuffer.CopyDataBytes(0, (uint)size, data.MutableBytes);
if (err != CMBlockBufferError.None)
continue;
allData.AppendData(data);
}
}
}
}
src = allData.ToArray();
}
}
}
}
But the byte array is not played. In my opinion, you need to convert pcm to mp3, etc. xamarin How to convert in c# environment?
In fact, pcm data may work well. If the pcm does not work properly, you should think back to the beginning. T.T.
c# ios xamarin
c# ios xamarin
edited Nov 21 at 8:15
James Westgate
8,64654258
8,64654258
asked Nov 21 at 3:10
최신혜
1
1
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
PCM is an encoding scheme,not a file format.If you want to convert your voice to mp3 .I recommend that you can use the package NAudio.Lame from the Nuget.
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 AudioFileReader(waveFileName))
using (var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate))
reader.CopyTo(writer);
}
// Convert MP3 file to WAV using NAudio classes only
public static void MP3ToWave(string mp3FileName, string waveFileName)
{
using (var reader = new Mp3FileReader(mp3FileName))
using (var writer = new WaveFileWriter(waveFileName, reader.WaveFormat))
reader.CopyTo(writer);
}
}
Thank you very much Lucas Zhang But the key is to create an mp3 mpmediaitem using the audio library mpmediapickercontroller. pcm data is only one of the processes. Do you know Lucas Zhang? How to convert mpmediaItem to WAV or MP3
– 최신혜
Nov 22 at 5:49
Can you provide the code about play the voice?
– Lucas Zhang - MSFT
Nov 22 at 7:01
I can provide you with music, but it is probably a useless mp3 file. There is an API in my application that uploads data to aws in byte format, and Android has already been tested.
– 최신혜
Nov 22 at 7:55
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404751%2fhow-to-convert-mp3-to-pcm%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
PCM is an encoding scheme,not a file format.If you want to convert your voice to mp3 .I recommend that you can use the package NAudio.Lame from the Nuget.
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 AudioFileReader(waveFileName))
using (var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate))
reader.CopyTo(writer);
}
// Convert MP3 file to WAV using NAudio classes only
public static void MP3ToWave(string mp3FileName, string waveFileName)
{
using (var reader = new Mp3FileReader(mp3FileName))
using (var writer = new WaveFileWriter(waveFileName, reader.WaveFormat))
reader.CopyTo(writer);
}
}
Thank you very much Lucas Zhang But the key is to create an mp3 mpmediaitem using the audio library mpmediapickercontroller. pcm data is only one of the processes. Do you know Lucas Zhang? How to convert mpmediaItem to WAV or MP3
– 최신혜
Nov 22 at 5:49
Can you provide the code about play the voice?
– Lucas Zhang - MSFT
Nov 22 at 7:01
I can provide you with music, but it is probably a useless mp3 file. There is an API in my application that uploads data to aws in byte format, and Android has already been tested.
– 최신혜
Nov 22 at 7:55
add a comment |
PCM is an encoding scheme,not a file format.If you want to convert your voice to mp3 .I recommend that you can use the package NAudio.Lame from the Nuget.
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 AudioFileReader(waveFileName))
using (var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate))
reader.CopyTo(writer);
}
// Convert MP3 file to WAV using NAudio classes only
public static void MP3ToWave(string mp3FileName, string waveFileName)
{
using (var reader = new Mp3FileReader(mp3FileName))
using (var writer = new WaveFileWriter(waveFileName, reader.WaveFormat))
reader.CopyTo(writer);
}
}
Thank you very much Lucas Zhang But the key is to create an mp3 mpmediaitem using the audio library mpmediapickercontroller. pcm data is only one of the processes. Do you know Lucas Zhang? How to convert mpmediaItem to WAV or MP3
– 최신혜
Nov 22 at 5:49
Can you provide the code about play the voice?
– Lucas Zhang - MSFT
Nov 22 at 7:01
I can provide you with music, but it is probably a useless mp3 file. There is an API in my application that uploads data to aws in byte format, and Android has already been tested.
– 최신혜
Nov 22 at 7:55
add a comment |
PCM is an encoding scheme,not a file format.If you want to convert your voice to mp3 .I recommend that you can use the package NAudio.Lame from the Nuget.
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 AudioFileReader(waveFileName))
using (var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate))
reader.CopyTo(writer);
}
// Convert MP3 file to WAV using NAudio classes only
public static void MP3ToWave(string mp3FileName, string waveFileName)
{
using (var reader = new Mp3FileReader(mp3FileName))
using (var writer = new WaveFileWriter(waveFileName, reader.WaveFormat))
reader.CopyTo(writer);
}
}
PCM is an encoding scheme,not a file format.If you want to convert your voice to mp3 .I recommend that you can use the package NAudio.Lame from the Nuget.
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 AudioFileReader(waveFileName))
using (var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate))
reader.CopyTo(writer);
}
// Convert MP3 file to WAV using NAudio classes only
public static void MP3ToWave(string mp3FileName, string waveFileName)
{
using (var reader = new Mp3FileReader(mp3FileName))
using (var writer = new WaveFileWriter(waveFileName, reader.WaveFormat))
reader.CopyTo(writer);
}
}
answered Nov 22 at 2:24
Lucas Zhang - MSFT
1,770127
1,770127
Thank you very much Lucas Zhang But the key is to create an mp3 mpmediaitem using the audio library mpmediapickercontroller. pcm data is only one of the processes. Do you know Lucas Zhang? How to convert mpmediaItem to WAV or MP3
– 최신혜
Nov 22 at 5:49
Can you provide the code about play the voice?
– Lucas Zhang - MSFT
Nov 22 at 7:01
I can provide you with music, but it is probably a useless mp3 file. There is an API in my application that uploads data to aws in byte format, and Android has already been tested.
– 최신혜
Nov 22 at 7:55
add a comment |
Thank you very much Lucas Zhang But the key is to create an mp3 mpmediaitem using the audio library mpmediapickercontroller. pcm data is only one of the processes. Do you know Lucas Zhang? How to convert mpmediaItem to WAV or MP3
– 최신혜
Nov 22 at 5:49
Can you provide the code about play the voice?
– Lucas Zhang - MSFT
Nov 22 at 7:01
I can provide you with music, but it is probably a useless mp3 file. There is an API in my application that uploads data to aws in byte format, and Android has already been tested.
– 최신혜
Nov 22 at 7:55
Thank you very much Lucas Zhang But the key is to create an mp3 mpmediaitem using the audio library mpmediapickercontroller. pcm data is only one of the processes. Do you know Lucas Zhang? How to convert mpmediaItem to WAV or MP3
– 최신혜
Nov 22 at 5:49
Thank you very much Lucas Zhang But the key is to create an mp3 mpmediaitem using the audio library mpmediapickercontroller. pcm data is only one of the processes. Do you know Lucas Zhang? How to convert mpmediaItem to WAV or MP3
– 최신혜
Nov 22 at 5:49
Can you provide the code about play the voice?
– Lucas Zhang - MSFT
Nov 22 at 7:01
Can you provide the code about play the voice?
– Lucas Zhang - MSFT
Nov 22 at 7:01
I can provide you with music, but it is probably a useless mp3 file. There is an API in my application that uploads data to aws in byte format, and Android has already been tested.
– 최신혜
Nov 22 at 7:55
I can provide you with music, but it is probably a useless mp3 file. There is an API in my application that uploads data to aws in byte format, and Android has already been tested.
– 최신혜
Nov 22 at 7:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404751%2fhow-to-convert-mp3-to-pcm%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown