Fix setting speaker ID for Android TTS Engine. (#530)
This commit is contained in:
@@ -184,7 +184,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// modelDir = "vits-zh-aishell3"
|
// modelDir = "vits-zh-aishell3"
|
||||||
// modelName = "vits-aishell3.onnx"
|
// modelName = "vits-aishell3.onnx"
|
||||||
// ruleFsts = "vits-zh-aishell3/rule.fst"
|
// ruleFsts = "vits-zh-aishell3/rule.fst"
|
||||||
// lexcion = "lexicon.txt"
|
// lexicon = "lexicon.txt"
|
||||||
|
|
||||||
if (dataDir != null) {
|
if (dataDir != null) {
|
||||||
val newDir = copyDataDir(modelDir)
|
val newDir = copyDataDir(modelDir)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.wrapContentHeight
|
import androidx.compose.foundation.layout.wrapContentHeight
|
||||||
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -32,6 +33,7 @@ import androidx.compose.runtime.mutableStateOf
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.k2fsa.sherpa.onnx.tts.engine.ui.theme.SherpaOnnxTtsEngineTheme
|
import com.k2fsa.sherpa.onnx.tts.engine.ui.theme.SherpaOnnxTtsEngineTheme
|
||||||
@@ -65,10 +67,14 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
var testText by remember { mutableStateOf("") }
|
var testText by remember { mutableStateOf("") }
|
||||||
|
|
||||||
OutlinedTextField(value = testText,
|
OutlinedTextField(
|
||||||
|
value = testText,
|
||||||
onValueChange = { testText = it },
|
onValueChange = { testText = it },
|
||||||
label = { Text("Test text") },
|
label = { Text("Test text") },
|
||||||
modifier = Modifier.fillMaxWidth().wrapContentHeight().padding(16.dp),
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.wrapContentHeight()
|
||||||
|
.padding(16.dp),
|
||||||
singleLine = false,
|
singleLine = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -76,11 +82,16 @@ class MainActivity : ComponentActivity() {
|
|||||||
if (numSpeakers > 1) {
|
if (numSpeakers > 1) {
|
||||||
Row {
|
Row {
|
||||||
Text("Speaker ID: (0-${numSpeakers - 1})")
|
Text("Speaker ID: (0-${numSpeakers - 1})")
|
||||||
Slider(
|
OutlinedTextField(
|
||||||
value = TtsEngine.speakerIdState.value.toFloat(),
|
value = TtsEngine.speakerIdState.value.toString(),
|
||||||
onValueChange = { TtsEngine.speakerId = it.toInt() },
|
onValueChange = {
|
||||||
valueRange = 0.0f..(numSpeakers - 1).toFloat(),
|
if (it.isEmpty() || it.isBlank()) {
|
||||||
steps = 1
|
TtsEngine.speakerId = 0
|
||||||
|
} else {
|
||||||
|
TtsEngine.speakerId = it.toString().toInt()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ object TtsEngine {
|
|||||||
// modelDir = "vits-zh-aishell3"
|
// modelDir = "vits-zh-aishell3"
|
||||||
// modelName = "vits-aishell3.onnx"
|
// modelName = "vits-aishell3.onnx"
|
||||||
// ruleFsts = "vits-zh-aishell3/rule.fst"
|
// ruleFsts = "vits-zh-aishell3/rule.fst"
|
||||||
// lexcion = "lexicon.txt"
|
// lexicon = "lexicon.txt"
|
||||||
// lang = "zho"
|
// lang = "zho"
|
||||||
|
|
||||||
if (dataDir != null) {
|
if (dataDir != null) {
|
||||||
|
|||||||
@@ -81,11 +81,11 @@ class TtsService : TextToSpeechService() {
|
|||||||
override fun onLoadLanguage(_lang: String?, _country: String?, _variant: String?): Int {
|
override fun onLoadLanguage(_lang: String?, _country: String?, _variant: String?): Int {
|
||||||
val lang = _lang ?: ""
|
val lang = _lang ?: ""
|
||||||
|
|
||||||
if (lang == TtsEngine.lang) {
|
return if (lang == TtsEngine.lang) {
|
||||||
TtsEngine.createTts(application)
|
TtsEngine.createTts(application)
|
||||||
return TextToSpeech.LANG_AVAILABLE
|
TextToSpeech.LANG_AVAILABLE
|
||||||
} else {
|
} else {
|
||||||
return TextToSpeech.LANG_NOT_SUPPORTED
|
TextToSpeech.LANG_NOT_SUPPORTED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user