0

My app already finds silence in audio as it is being recorded on an iOS device. I compare background and speaking volumes from samples then compare it and so far it has been pretty accurate. This way I save the audio into smaller multiple files, yet without cutting words.

Now I would like to do the same with prerecorded audio files (m4a).

  1. Open an m4a audio file on my iOS device
  2. Read 0.5 seconds of an audio file based on it's format, channels, etc,
  3. Use my detect silence function to determine whether to read more or less data

While I have no problem opening the files and getting their format (below), I am unsure as to how to calculate how much of the data to read in to get a sample. If I determine just silence, read more data in. If I determine there's a spoken word, read less data so as not to clip the word.

I have tried googling to get info as to how to interpret the format of the file (sampling rate, channels, etc. )to figure out how much to read, but have not been able to find any.

   //left out error checking in this sample
   let input = try? AVAudioFile(forReading: url) else {
       return nil
    }
    
   let buffer = AVAudioPCMBuffer(pcmFormat: input.processingFormat, frameCapacity: AVAudioFrameCount(input.length)) else {
       return nil
    }
    
    do {
       // reads entire audio file
       try input.read(into: buffer)
    } catch {
       return nil
    }
Bartender1382
  • 195
  • 1
  • 10

0 Answers0