      - parameter data: The WAV-formatted audio file produced by Watson Text to Speech. The
             byte data will be analyzed and repaired in-place.
      */
-    private static func repairWAVHeader(data: NSMutableData) {
+    private static func repairWAVHeader(data: inout Data) {
         
         // resources for WAV header format:
         // [1] http://unusedino.de/ec64/technical/formats/wav.html
         // [2] http://soundfile.sapp.org/doc/WaveFormat/
         
         // update RIFF chunk size
-        let fileLength = data.length
+        let fileLength = data.count
         var riffChunkSize = UInt32(fileLength - 8)
-        let riffChunkSizeRange = NSMakeRange(4, 4)
-        data.replaceBytes(in: riffChunkSizeRange, withBytes: &riffChunkSize)
+        let riffChunkSizeData = Data(bytes: &riffChunkSize, count: MemoryLayout<UInt32>.stride)
+        data.replaceSubrange(Range(uncheckedBounds: (lower: 4, upper: 8)), with: riffChunkSizeData)
         
         // find data subchunk
         var subchunkID: String?

        }
        
        // compute data subchunk size (excludes id and size fields)
        var dataSubchunkSize = UInt32(data.length - fieldOffset - fieldSize)
        
        // update data subchunk size
        let dataSubchunkSizeRange = NSMakeRange(fieldOffset, fieldSize)
        data.replaceBytes(in: dataSubchunkSizeRange, withBytes: &dataSubchunkSize)
    }
}

     - returns: A String initialized by converting the given big-endian byte buffer into
            Unicode characters using a UTF-8 encoding.
     */
    private static func dataToUTF8String(data: Data, offset: Int, length: Int) -> String? {
        let range = Range(uncheckedBounds: (lower: offset, upper: offset + length))
        let subdata = data.subdata(in: range)
        return String(data: subdata, encoding: String.Encoding.utf8)
    }
    
