Committed by
GitHub
Refactor the UI of Android TTS engine (#533)
正在显示
1 个修改的文件
包含
31 行增加
和
24 行删除
| @@ -56,45 +56,52 @@ class MainActivity : ComponentActivity() { | @@ -56,45 +56,52 @@ class MainActivity : ComponentActivity() { | ||
| 56 | TopAppBar(title = { Text("Next-gen Kaldi: TTS") }) | 56 | TopAppBar(title = { Text("Next-gen Kaldi: TTS") }) |
| 57 | }) { | 57 | }) { |
| 58 | Box(modifier = Modifier.padding(it)) { | 58 | Box(modifier = Modifier.padding(it)) { |
| 59 | - Column { | ||
| 60 | - Row { | ||
| 61 | - Text("Speed") | 59 | + Column(modifier = Modifier.padding(16.dp)) { |
| 60 | + Column { | ||
| 61 | + Text("Speed " + String.format("%.1f", TtsEngine.speed)) | ||
| 62 | Slider( | 62 | Slider( |
| 63 | value = TtsEngine.speedState.value, | 63 | value = TtsEngine.speedState.value, |
| 64 | onValueChange = { TtsEngine.speed = it }, | 64 | onValueChange = { TtsEngine.speed = it }, |
| 65 | - valueRange = 0.2F..3.0F | 65 | + valueRange = 0.2F..3.0F, |
| 66 | + modifier = Modifier.fillMaxWidth() | ||
| 66 | ) | 67 | ) |
| 67 | } | 68 | } |
| 68 | var testText by remember { mutableStateOf("") } | 69 | var testText by remember { mutableStateOf("") } |
| 69 | 70 | ||
| 71 | + | ||
| 72 | + val numSpeakers = TtsEngine.tts!!.numSpeakers() | ||
| 73 | + if (numSpeakers > 1) { | ||
| 74 | + OutlinedTextField( | ||
| 75 | + value = TtsEngine.speakerIdState.value.toString(), | ||
| 76 | + onValueChange = { | ||
| 77 | + if (it.isEmpty() || it.isBlank()) { | ||
| 78 | + TtsEngine.speakerId = 0 | ||
| 79 | + } else { | ||
| 80 | + TtsEngine.speakerId = it.toString().toInt() | ||
| 81 | + } | ||
| 82 | + }, | ||
| 83 | + label = { | ||
| 84 | + Text("Speaker ID: (0-${numSpeakers - 1})") | ||
| 85 | + }, | ||
| 86 | + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), | ||
| 87 | + modifier = Modifier | ||
| 88 | + .fillMaxWidth() | ||
| 89 | + .padding(bottom = 16.dp) | ||
| 90 | + .wrapContentHeight(), | ||
| 91 | + ) | ||
| 92 | + } | ||
| 93 | + | ||
| 70 | OutlinedTextField( | 94 | OutlinedTextField( |
| 71 | value = testText, | 95 | value = testText, |
| 72 | onValueChange = { testText = it }, | 96 | onValueChange = { testText = it }, |
| 73 | - label = { Text("Test text") }, | 97 | + label = { Text("Please input your text here") }, |
| 74 | modifier = Modifier | 98 | modifier = Modifier |
| 75 | .fillMaxWidth() | 99 | .fillMaxWidth() |
| 76 | - .wrapContentHeight() | ||
| 77 | - .padding(16.dp), | 100 | + .padding(bottom = 16.dp) |
| 101 | + .wrapContentHeight(), | ||
| 78 | singleLine = false, | 102 | singleLine = false, |
| 79 | ) | 103 | ) |
| 80 | 104 | ||
| 81 | - val numSpeakers = TtsEngine.tts!!.numSpeakers() | ||
| 82 | - if (numSpeakers > 1) { | ||
| 83 | - Row { | ||
| 84 | - Text("Speaker ID: (0-${numSpeakers - 1})") | ||
| 85 | - OutlinedTextField( | ||
| 86 | - value = TtsEngine.speakerIdState.value.toString(), | ||
| 87 | - onValueChange = { | ||
| 88 | - if (it.isEmpty() || it.isBlank()) { | ||
| 89 | - TtsEngine.speakerId = 0 | ||
| 90 | - } else { | ||
| 91 | - TtsEngine.speakerId = it.toString().toInt() | ||
| 92 | - } | ||
| 93 | - }, | ||
| 94 | - keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number) | ||
| 95 | - ) | ||
| 96 | - } | ||
| 97 | - } | ||
| 98 | Row { | 105 | Row { |
| 99 | Button( | 106 | Button( |
| 100 | modifier = Modifier.padding(20.dp), | 107 | modifier = Modifier.padding(20.dp), |
-
请 注册 或 登录 后发表评论