 
     internal func writeStart(settings: RecognitionSettings) {
         guard state != .disconnected else { return }
-        guard let start = try? settings.toJSON().serializeString() else { return }
+        guard let data = try? JSONEncoder().encode(settings) else { return }
+        guard let start = String(data: data, encoding: .utf8) else { return }
         queue.addOperation {
             self.socket.write(string: start)
             self.results = SpeechRecognitionResults()

        }
    }

    private func onResultsMessage(event: SpeechRecognitionEvent) {
        state = .transcribing
        results.addResults(event: event)
        onResults?(results)
    }


    }

    internal func websocketDidReceiveMessage(socket: WebSocketClient, text: String) {
        guard let json = text.data(using: .utf8) else { return }
        let decoder = JSONDecoder()
        if let state = try? decoder.decode(RecognitionState.self, from: json) {
            onStateMessage(state: state)
        } else if let object = try? decoder.decode([String: String].self, from: json), let error = object["error"] {
            onErrorMessage(error: error)
        } else if let results = try? decoder.decode(SpeechRecognitionResults.self, from: json) {
            // all properties of `SpeechRecognitionResults` are optional, so this block will always
            // execute unless the message has already been parsed as a `RecognitionState` or error
            onResultsMessage(results: results)
        }
    }

