Committed by
GitHub
Ensure input for speaker ID is a valid number. (#552)
Fix #547
正在显示
1 个修改的文件
包含
7 行增加
和
1 行删除
| @@ -38,6 +38,7 @@ import androidx.compose.ui.tooling.preview.Preview | @@ -38,6 +38,7 @@ import androidx.compose.ui.tooling.preview.Preview | ||
| 38 | import androidx.compose.ui.unit.dp | 38 | import androidx.compose.ui.unit.dp |
| 39 | import com.k2fsa.sherpa.onnx.tts.engine.ui.theme.SherpaOnnxTtsEngineTheme | 39 | import com.k2fsa.sherpa.onnx.tts.engine.ui.theme.SherpaOnnxTtsEngineTheme |
| 40 | import java.io.File | 40 | import java.io.File |
| 41 | +import java.lang.NumberFormatException | ||
| 41 | 42 | ||
| 42 | const val TAG = "sherpa-onnx-tts-engine" | 43 | const val TAG = "sherpa-onnx-tts-engine" |
| 43 | 44 | ||
| @@ -77,7 +78,12 @@ class MainActivity : ComponentActivity() { | @@ -77,7 +78,12 @@ class MainActivity : ComponentActivity() { | ||
| 77 | if (it.isEmpty() || it.isBlank()) { | 78 | if (it.isEmpty() || it.isBlank()) { |
| 78 | TtsEngine.speakerId = 0 | 79 | TtsEngine.speakerId = 0 |
| 79 | } else { | 80 | } else { |
| 80 | - TtsEngine.speakerId = it.toString().toInt() | 81 | + try { |
| 82 | + TtsEngine.speakerId = it.toString().toInt() | ||
| 83 | + } catch (ex: NumberFormatException) { | ||
| 84 | + Log.i(TAG, "Invalid input: ${it}") | ||
| 85 | + TtsEngine.speakerId = 0 | ||
| 86 | + } | ||
| 81 | } | 87 | } |
| 82 | }, | 88 | }, |
| 83 | label = { | 89 | label = { |
-
请 注册 或 登录 后发表评论