             return 
         }
         
+        
         let chunkSize: Int = watsonFrameSize * 2
         var offset : Int = 0
         
         var ptr = UnsafeMutablePointer<UInt8>(buffer.mAudioData)
         
-        repeat {
-        
-            let thisChunkSize = length - offset > chunkSize ? chunkSize : length - offset
-            ptr += offset
-            
-            let chunk = NSData(bytesNoCopy: ptr, length: thisChunkSize, freeWhenDone: false)
-            
-            let compressed = data.opusEncoder.encode(chunk, frameSize: Int32(watsonFrameSize))
-            
-            if compressed.length != 0 {
-                // Log.sharedLogger.info("Compressed the packet")
-                
-                let newData = data.oggEncoder.writePacket(compressed, frameSize: Int32(watsonFrameSize))
-                
-                if newData != nil {
-                    // Log.sharedLogger.info("Wrote an OGG packet")
-                    
-                        if let socket = data.socket {
-                            
-                            Log.sharedLogger.info("Added the audio to the queue")
-                            let o1 = AudioUploadOperation(data: newData, socket: socket)
-                            data.audioUploadQueue.addOperation(o1)
-                        } else {
-                            
-                            Log.sharedLogger.warning("Could not get handle to socket")
-                            
-                        }
-        
-                    
-                    
-                }
-            }
-            
-            offset += thisChunkSize
-        
-        } while offset < length
-        
+        let newData = NSData(bytesNoCopy: ptr, length: Int(buffer.mAudioDataByteSize), freeWhenDone: false)
+        
+        Log.sharedLogger.info("Added the audio to the queue")
+        //let o1 = AudioUploadOperation(data: newData, socket: data.socket!)
+        //data.audioUploadQueue.addOperation(o1)
         
         
         // Tell the buffer it's free to accept more data

    
    init() {
        
        super.init(serviceURL: serviceURL)
        
        opus.createEncoder(Int32(WATSON_AUDIO_SAMPLE_RATE))
        
        audioUploadQueue = NSOperationQueue()
        audioUploadQueue.name = "Audio upload"
        audioUploadQueue.maxConcurrentOperationCount = 1
        
    }
    

 **/

import Foundation

import ObjectMapper

/**
    The IBM® Speech to Text service provides an Application Programming Interface (API) that
    enables you to add speech transcription capabilities to your applications.
*/
public class SpeechToText {
    
    
    
    private let WATSON_AUDIO_SAMPLE_RATE = 16000
    private let WATSON_AUDIO_FRAME_SIZE = 160
    
    
    // NSOperationQueues
    var transcriptionQueue: NSOperationQueue!
    
    
    public var delegate : SpeechToTextDelegate?
    
    
    
    private let opus: OpusHelper = OpusHelper()
    private let ogg: OggHelper = OggHelper()
    
    private let watsonSocket = WatsonSocket()
   
    
    var audioData: NSData?
    
