title: How to convert CMSampleBuffer to Data in Swift?
body: <p>I need to convert <code>CMSampleBuffer</code> to <code>Data</code> format. I am using one Third party framework for audio related task. That framework gives me the streaming (i.e Real Time audio) audio in <code>CMSampleBuffer</code> object.</p>
  
  <p>Like this:</p>
  
  <pre><code>func didAudioStreaming(audioSample: CMSampleBuffer!) {
      //Here I need to conver this to Data format. 
      //Because I am using GRPC framework for Audio Recognization, 
  }
  </code></pre>
  
  <p>Please provide me the steps to convert the <code>CMSampleBuffer</code> to <code>Data</code>.</p>
  
  <p>FYI</p>
  
  <pre><code>    let formatDesc:CMFormatDescription? = CMSampleBufferGetFormatDescription(audioSample)
  
      &lt;CMAudioFormatDescription 0x17010d890 [0x1b453ebb8]&gt; {
      mediaType:'soun' 
      mediaSubType:'lpcm' 
      mediaSpecific: {
          ASBD: {
              mSampleRate: 16000.000000 
              mFormatID: 'lpcm' 
              mFormatFlags: 0xc 
              mBytesPerPacket: 2 
              mFramesPerPacket: 1 
              mBytesPerFrame: 2 
              mChannelsPerFrame: 1 
              mBitsPerChannel: 16     } 
          cookie: {(null)} 
          ACL: {(null)}
          FormatList Array: {(null)} 
      } 
      extensions: {(null)}
  }
  </code></pre>