Upload TTS APKs to huggingface (#400)

This commit is contained in:
Fangjun Kuang
2023-10-29 18:30:43 +08:00
committed by GitHub
parent 4115f97bf0
commit 1544a577e0
8 changed files with 286 additions and 92 deletions

View File

@@ -84,6 +84,8 @@ class MainActivity : AppCompatActivity() {
val ok = audio.samples.size > 0 && audio.save(filename)
if (ok) {
play.isEnabled = true
// Play automatically after generation
onClickPlay()
}
}
@@ -97,10 +99,24 @@ class MainActivity : AppCompatActivity() {
}
fun initTts() {
// 0 - vits-vctk (multi-speaker, English)
// 1 - vits-zh-aishell3 (multi-speaker, Chinese)
val type = 0
val config = getOfflineTtsConfig(type = type, debug = true)!!
var modelDir :String?
var modelName :String?
// The purpose of such a design is to make the CI test easier
// Please see
// https://github.com/k2-fsa/sherpa-onnx/blob/master/scripts/apk/generate-tts-apk-script.py
modelDir = null
modelName = null
// Example 1:
// modelDir = "vits-vctk"
// modelName = "vits-vctk.onnx"
// Example 2:
// modelDir = "vits-piper-en_US-lessac-medium"
// modelName = "en_US-lessac-medium.onnx"
val config = getOfflineTtsConfig(modelDir = modelDir!!, modelName = modelName!!)!!
tts = OfflineTts(assetManager = application.assets, config = config)
}
}

View File

@@ -116,45 +116,17 @@ class OfflineTts(
// please refer to
// https://k2-fsa.github.io/sherpa/onnx/tts/pretrained_models/index.html
// to download models
//
// You can change the type as you wish
fun getOfflineTtsConfig(type: Int, debug: Boolean = false): OfflineTtsConfig? {
when (type) {
0 -> {
val modelDir = "vits-vctk"
return OfflineTtsConfig(
model = OfflineTtsModelConfig(
vits = OfflineTtsVitsModelConfig(
model = "$modelDir/vits-vctk.onnx",
lexicon = "$modelDir/lexicon.txt",
tokens = "$modelDir/tokens.txt"
),
numThreads = 2,
debug = debug,
provider = "cpu",
)
)
}
1 -> {
val modelDir = "vits-zh-aishell3"
return OfflineTtsConfig(
model = OfflineTtsModelConfig(
vits = OfflineTtsVitsModelConfig(
model = "$modelDir/vits-aishell3.onnx",
lexicon = "$modelDir/lexicon.txt",
tokens = "$modelDir/tokens.txt"
),
numThreads = 2,
debug = debug,
provider = "cpu",
)
)
}
}
println("Unsupported type $type")
return null
fun getOfflineTtsConfig(modelDir: String, modelName: String): OfflineTtsConfig? {
return OfflineTtsConfig(
model = OfflineTtsModelConfig(
vits = OfflineTtsVitsModelConfig(
model = "$modelDir/$modelName",
lexicon = "$modelDir/lexicon.txt",
tokens = "$modelDir/tokens.txt"
),
numThreads = 2,
debug = false,
provider = "cpu",
)
)
}