How do I change audio file format settings using code in iOS using Swift?

Is there a way to change the audio characteristics of an audio file using code in iOS?


For instance, I need to change the audio file characteristics to the following:


  • single-channel (monaural)
  • little-endian
  • unheadered
  • 16-bit signed
  • PCM
  • sampled at 16000 Hz


I need to actually open an mp3 file from my iOS app and change the characteristics, then save the file with the new characteristics.

Replies

Take a look at AVAudioFile:


https://developer.apple.com/documentation/avfoundation/avaudiofile


For your input file, specify a AVAudioCommonFormat to use for the processing format that's as close to the output characteristics you want. For the output file, use the same processing format, and use the settings dictionary for anything else you need (that's not specifiable in the format).