fix a bug
This commit is contained in:
@@ -258,9 +258,14 @@ class OralTrainerController internal constructor(
|
||||
|
||||
fun playCurrentSentenceAndStop() {
|
||||
val sentence = currentSentence() ?: return
|
||||
player.seekTo(sentence.startMs)
|
||||
playSentenceAndStop(sentence.startMs, sentence.index)
|
||||
}
|
||||
|
||||
/** Seek to a known sentence and stop automatically when that sentence ends. */
|
||||
fun playSentenceAndStop(startMs: Long, sentenceIndex: Int) {
|
||||
stopAtSentenceEnd = true
|
||||
stopAtSentenceEndIndex = sentence.index
|
||||
stopAtSentenceEndIndex = sentenceIndex
|
||||
player.seekTo(max(0L, startMs))
|
||||
player.play()
|
||||
refreshSentenceBoundaryGuard()
|
||||
}
|
||||
|
||||
@@ -67,6 +67,21 @@ data class UserDubShare(
|
||||
val createdAt: String,
|
||||
)
|
||||
|
||||
data class DubShareSegmentDetail(
|
||||
val index: Int,
|
||||
val overallScore: Float,
|
||||
val recognizedText: String,
|
||||
val scoreDetails: Map<String, Float>,
|
||||
val audioUrl: String,
|
||||
)
|
||||
|
||||
data class DubShareDetail(
|
||||
val shareId: String,
|
||||
val videoHash: String,
|
||||
val title: String,
|
||||
val segments: List<DubShareSegmentDetail>,
|
||||
)
|
||||
|
||||
class UserApiException(
|
||||
val statusCode: Int,
|
||||
responseBody: String,
|
||||
@@ -150,6 +165,13 @@ class UserApi internal constructor(
|
||||
onComplete: (Result<List<UserDubShare>>) -> Unit,
|
||||
): CancellableRequest = submitObject(onComplete, token) { parseDubShares(getBlocking(it, "api/v1/me/dub-shares")) }
|
||||
|
||||
fun dubShareDetail(
|
||||
shareId: String,
|
||||
onComplete: (Result<DubShareDetail>) -> Unit,
|
||||
): CancellableRequest = submit(onComplete) {
|
||||
parseDubShareDetail(JSONObject(request("api/v1/dub-shares/$shareId", method = "GET")))
|
||||
}
|
||||
|
||||
fun release() {
|
||||
executor.shutdownNow()
|
||||
}
|
||||
@@ -252,6 +274,34 @@ class UserApi internal constructor(
|
||||
)
|
||||
}
|
||||
|
||||
private fun parseDubShareDetail(root: JSONObject): DubShareDetail {
|
||||
val segmentsJson = root.optJSONArray("segments") ?: JSONArray()
|
||||
val segments = List(segmentsJson.length()) { index ->
|
||||
val item = segmentsJson.getJSONObject(index)
|
||||
val detailsJson = item.optJSONObject("score_details") ?: JSONObject()
|
||||
val scoreDetails = buildMap<String, Float> {
|
||||
for (key in detailsJson.keys()) {
|
||||
if (!detailsJson.isNull(key)) {
|
||||
put(key, detailsJson.optDouble(key).toFloat())
|
||||
}
|
||||
}
|
||||
}
|
||||
DubShareSegmentDetail(
|
||||
index = item.getInt("index"),
|
||||
overallScore = item.optDouble("overall_score", 0.0).toFloat(),
|
||||
recognizedText = item.optString("recognized_text"),
|
||||
scoreDetails = scoreDetails,
|
||||
audioUrl = item.getString("audio_url"),
|
||||
)
|
||||
}
|
||||
return DubShareDetail(
|
||||
shareId = root.getString("share_id"),
|
||||
videoHash = root.getString("video_hash"),
|
||||
title = root.optString("title"),
|
||||
segments = segments,
|
||||
)
|
||||
}
|
||||
|
||||
private fun request(
|
||||
path: String,
|
||||
token: String? = null,
|
||||
|
||||
Reference in New Issue
Block a user