2014-10-11 68 views
0

在Android中,我使用下面的代碼行生成的字節數組如何在Objective-C中從字節數組創建音頻?

byte audioData[]; 
//. 
//fill audioData 
//. 
final AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 
      sampleRateInHz, AudioFormat.CHANNEL_CONFIGURATION_MONO, 
      AudioFormat.ENCODING_PCM_16BIT, audioData.lenght, 
      AudioTrack.MODE_STATIC); 
audioTrack.write(audioData, 0, audioData.length); 
audioTrack.play(); 

聲音我怎麼能在IOS SDK實現這一目標。是否有任何等效庫從byteArray生成聲音?

回答

0

你可以嘗試:

NSData *audioData = // take audioData from wherever it is 

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; 
[[AVAudioSession sharedInstance] setActive:YES error:nil]; 

self.audioPlayer = [[AVAudioPlayer alloc] initWithData:audioData error:nil]; // audioPlayer must be a strong property. Do not create it locally 

[self.audioPlayer prepareToPlay]; 
[self.audioPlayer play]; 

確保導入AVFoundation模塊