|
|
|
@ -25,6 +25,13 @@ class XunFeiAsrHelper(private val context: Context) { |
|
|
|
private var currentSessionId = "" |
|
|
|
|
|
|
|
fun start(callback: AzureAsrHelper.ContinuousRecognizeCallback) { |
|
|
|
try { |
|
|
|
webSocket?.cancel() |
|
|
|
webSocket = null |
|
|
|
} catch (e: Exception) { |
|
|
|
Log.e(tag, "Clear previous websocket failed: ${e.message}") |
|
|
|
} |
|
|
|
|
|
|
|
currentSessionId = UUID.randomUUID().toString() |
|
|
|
|
|
|
|
val url = getWebSocketUrl() |
|
|
|
@ -64,8 +71,15 @@ class XunFeiAsrHelper(private val context: Context) { |
|
|
|
} |
|
|
|
|
|
|
|
fun stop() { |
|
|
|
webSocket?.let { ws: WebSocket -> |
|
|
|
ws.send("{\"end\": true}") |
|
|
|
try { |
|
|
|
webSocket?.let { ws: WebSocket -> |
|
|
|
ws.send("{\"end\": true}") |
|
|
|
ws.close(1000, "User stopped") |
|
|
|
} |
|
|
|
} catch (e: Exception) { |
|
|
|
Log.e(tag, "Stop Xunfei failed: ${e.message}") |
|
|
|
} finally { |
|
|
|
webSocket = null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|