本项目是基于 Azure 文本转语音服务 实现
添加依赖:
dependencies {
implementation("top.limbang:text-to-speech:1.0.2")
}
编写 SSML 参考SSML语法
val ssml = createSSML().speak{
voice(XiaoxiaoNeural()) {
+"你好我是${it.localName}"
}
}
val out = FileOutputStream("123.mp3")
runBlocking {
// 需要在协程里面执行
val speech = TTS.convert(ssml)
if (speech.isNotEmpty()) withContext(Dispatchers.IO) {
out.write(speech)
out.flush()
out.close()
}
}