AudioKit / Cookbook

Canonical Examples for Using the AudioKit Framework
MIT License
639 stars 103 forks source link

Does Audiokit provide any functionalites to play audio from NSData #130

Closed NewajShovo closed 1 year ago

NewajShovo commented 1 year ago

Description

I have been using "The Amazing Audio Engine" and "AEAudioPlayable" for playing an audio stored in database as NSData. I want to replace the current framework to Audiokit but problem is that, I couldn't find any way to do it using audiokit.

Proposed Solution

Is there any way currently here to implement this??

Describe Alternatives You've Considered

Is there any way currently here to implement this??

Additional Context

No response

emurray2 commented 1 year ago

Yes, please see: https://stackoverflow.com/questions/28048568/convert-avaudiopcmbuffer-to-nsdata-and-back. Then you can create an AudioPlayer instance and set its buffer using myPlayer.buffer = AVAudioPCMBuffer(myData).

NewajShovo commented 1 year ago

@emurray2 thanks for the update. Let me dive into the problem a bit more.

Basically, I have an array of NSData where a chunk of data is saved. I passed that data as an AEAudioPlayable instance in the "The Amazing Audio Engine" framework to play that data. Each chunk is of 0.06 seconds.

So, I want to achieve this using Audiokit. is that possible so that I can pass each chunk of data that plays for 0.06 seconds? Though I have to deal with decoding the data as well but I am ignoring that for now.

Any help would be highly appreciated.

emurray2 commented 1 year ago

Sure thing, here are the steps:

  1. Create an instance of the audio player class var myPlayer = AudioPlayer()

  2. Convert your decoded NSData from Data to AVAudioPCMBuffer using the code in the Stackoverflow link above

  3. Set the buffer of your audio player to the chunk of data you want to play myPlayer.buffer = myData

  4. Play the player myPlayer.play()

PS: In general issues are for if you are experiencing a bug with AudioKit rather than questions on how to implement code. If you want to discuss this more, please join our discord.