正在显示
46 个修改的文件
包含
1151 行增加
和
15 行删除
| @@ -38,6 +38,7 @@ jobs: | @@ -38,6 +38,7 @@ jobs: | ||
| 38 | shell: bash | 38 | shell: bash |
| 39 | run: | | 39 | run: | |
| 40 | export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME | 40 | export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME |
| 41 | + ./build-apk-tts.sh | ||
| 41 | ./build-apk-vad.sh | 42 | ./build-apk-vad.sh |
| 42 | ./build-apk-two-pass.sh | 43 | ./build-apk-two-pass.sh |
| 43 | ./build-apk.sh | 44 | ./build-apk.sh |
android/SherpaOnnxTts/.gitignore
0 → 100644
android/SherpaOnnxTts/app/.gitignore
0 → 100644
| 1 | +/build |
android/SherpaOnnxTts/app/build.gradle
0 → 100644
| 1 | +plugins { | ||
| 2 | + id 'com.android.application' | ||
| 3 | + id 'org.jetbrains.kotlin.android' | ||
| 4 | +} | ||
| 5 | + | ||
| 6 | +android { | ||
| 7 | + namespace 'com.k2fsa.sherpa.onnx' | ||
| 8 | + compileSdk 32 | ||
| 9 | + | ||
| 10 | + defaultConfig { | ||
| 11 | + applicationId "com.k2fsa.sherpa.onnx" | ||
| 12 | + minSdk 21 | ||
| 13 | + targetSdk 32 | ||
| 14 | + versionCode 1 | ||
| 15 | + versionName "1.0" | ||
| 16 | + | ||
| 17 | + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + buildTypes { | ||
| 21 | + release { | ||
| 22 | + minifyEnabled false | ||
| 23 | + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
| 24 | + } | ||
| 25 | + } | ||
| 26 | + compileOptions { | ||
| 27 | + sourceCompatibility JavaVersion.VERSION_1_8 | ||
| 28 | + targetCompatibility JavaVersion.VERSION_1_8 | ||
| 29 | + } | ||
| 30 | + kotlinOptions { | ||
| 31 | + jvmTarget = '1.8' | ||
| 32 | + } | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +dependencies { | ||
| 36 | + | ||
| 37 | + implementation 'com.android.support.constraint:constraint-layout:1.1.3' | ||
| 38 | + implementation 'androidx.core:core-ktx:1.7.0' | ||
| 39 | + implementation 'com.google.android.material:material:1.9.0' | ||
| 40 | + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | ||
| 41 | + testImplementation 'junit:junit:4.13.2' | ||
| 42 | + androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
| 43 | + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
| 44 | +} |
android/SherpaOnnxTts/app/proguard-rules.pro
0 → 100644
| 1 | +# Add project specific ProGuard rules here. | ||
| 2 | +# You can control the set of applied configuration files using the | ||
| 3 | +# proguardFiles setting in build.gradle. | ||
| 4 | +# | ||
| 5 | +# For more details, see | ||
| 6 | +# http://developer.android.com/guide/developing/tools/proguard.html | ||
| 7 | + | ||
| 8 | +# If your project uses WebView with JS, uncomment the following | ||
| 9 | +# and specify the fully qualified class name to the JavaScript interface | ||
| 10 | +# class: | ||
| 11 | +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
| 12 | +# public *; | ||
| 13 | +#} | ||
| 14 | + | ||
| 15 | +# Uncomment this to preserve the line number information for | ||
| 16 | +# debugging stack traces. | ||
| 17 | +#-keepattributes SourceFile,LineNumberTable | ||
| 18 | + | ||
| 19 | +# If you keep the line number information, uncomment this to | ||
| 20 | +# hide the original source file name. | ||
| 21 | +#-renamesourcefileattribute SourceFile |
android/SherpaOnnxTts/app/src/androidTest/java/com/k2fsa/sherpa/onnx/ExampleInstrumentedTest.kt
0 → 100644
| 1 | +package com.k2fsa.sherpa.onnx | ||
| 2 | + | ||
| 3 | +import androidx.test.platform.app.InstrumentationRegistry | ||
| 4 | +import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| 5 | + | ||
| 6 | +import org.junit.Test | ||
| 7 | +import org.junit.runner.RunWith | ||
| 8 | + | ||
| 9 | +import org.junit.Assert.* | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * Instrumented test, which will execute on an Android device. | ||
| 13 | + * | ||
| 14 | + * See [testing documentation](http://d.android.com/tools/testing). | ||
| 15 | + */ | ||
| 16 | +@RunWith(AndroidJUnit4::class) | ||
| 17 | +class ExampleInstrumentedTest { | ||
| 18 | + @Test | ||
| 19 | + fun useAppContext() { | ||
| 20 | + // Context of the app under test. | ||
| 21 | + val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
| 22 | + assertEquals("com.k2fsa.sherpa.onnx", appContext.packageName) | ||
| 23 | + } | ||
| 24 | +} |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | + xmlns:tools="http://schemas.android.com/tools"> | ||
| 4 | + | ||
| 5 | + <application | ||
| 6 | + android:allowBackup="true" | ||
| 7 | + android:dataExtractionRules="@xml/data_extraction_rules" | ||
| 8 | + android:fullBackupContent="@xml/backup_rules" | ||
| 9 | + android:icon="@mipmap/ic_launcher" | ||
| 10 | + android:label="@string/app_name" | ||
| 11 | + android:roundIcon="@mipmap/ic_launcher_round" | ||
| 12 | + android:supportsRtl="true" | ||
| 13 | + android:theme="@style/Theme.SherpaOnnxTts" | ||
| 14 | + tools:targetApi="31"> | ||
| 15 | + <activity | ||
| 16 | + android:name=".MainActivity" | ||
| 17 | + android:exported="true"> | ||
| 18 | + <intent-filter> | ||
| 19 | + <action android:name="android.intent.action.MAIN" /> | ||
| 20 | + | ||
| 21 | + <category android:name="android.intent.category.LAUNCHER" /> | ||
| 22 | + </intent-filter> | ||
| 23 | + | ||
| 24 | + <meta-data | ||
| 25 | + android:name="android.app.lib_name" | ||
| 26 | + android:value="" /> | ||
| 27 | + </activity> | ||
| 28 | + </application> | ||
| 29 | + | ||
| 30 | +</manifest> |
| 1 | +package com.k2fsa.sherpa.onnx | ||
| 2 | + | ||
| 3 | +import android.media.MediaPlayer | ||
| 4 | +import android.net.Uri | ||
| 5 | +import android.os.Bundle | ||
| 6 | +import android.util.Log | ||
| 7 | +import android.widget.Button | ||
| 8 | +import android.widget.EditText | ||
| 9 | +import android.widget.Toast | ||
| 10 | +import androidx.appcompat.app.AppCompatActivity | ||
| 11 | +import java.io.File | ||
| 12 | + | ||
| 13 | +const val TAG = "sherpa-onnx" | ||
| 14 | + | ||
| 15 | +class MainActivity : AppCompatActivity() { | ||
| 16 | + private lateinit var tts: OfflineTts | ||
| 17 | + private lateinit var text: EditText | ||
| 18 | + private lateinit var sid: EditText | ||
| 19 | + private lateinit var speed: EditText | ||
| 20 | + private lateinit var generate: Button | ||
| 21 | + private lateinit var play: Button | ||
| 22 | + private var hasFile: Boolean = false | ||
| 23 | + | ||
| 24 | + override fun onCreate(savedInstanceState: Bundle?) { | ||
| 25 | + super.onCreate(savedInstanceState) | ||
| 26 | + setContentView(R.layout.activity_main) | ||
| 27 | + | ||
| 28 | + Log.i(TAG, "Start to initialize TTS") | ||
| 29 | + initTts() | ||
| 30 | + Log.i(TAG, "Finish initializing TTS") | ||
| 31 | + | ||
| 32 | + text = findViewById(R.id.text) | ||
| 33 | + sid = findViewById(R.id.sid) | ||
| 34 | + speed = findViewById(R.id.speed) | ||
| 35 | + | ||
| 36 | + generate = findViewById(R.id.generate) | ||
| 37 | + play = findViewById(R.id.play) | ||
| 38 | + | ||
| 39 | + generate.setOnClickListener { onClickGenerate() } | ||
| 40 | + play.setOnClickListener { onClickPlay() } | ||
| 41 | + | ||
| 42 | + sid.setText("0") | ||
| 43 | + speed.setText("1.0") | ||
| 44 | + | ||
| 45 | + // we will change sampleText here in the CI | ||
| 46 | + val sampleText = "" | ||
| 47 | + text.setText(sampleText) | ||
| 48 | + | ||
| 49 | + play.isEnabled = false; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + fun onClickGenerate() { | ||
| 53 | + val sidInt = sid.text.toString().toIntOrNull() | ||
| 54 | + if (sidInt == null || sidInt < 0) { | ||
| 55 | + Toast.makeText( | ||
| 56 | + applicationContext, | ||
| 57 | + "Please input a non-negative integer for speaker ID!", | ||
| 58 | + Toast.LENGTH_SHORT | ||
| 59 | + ).show() | ||
| 60 | + return | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + val speedFloat = speed.text.toString().toFloatOrNull() | ||
| 64 | + if (speedFloat == null || speedFloat <= 0) { | ||
| 65 | + Toast.makeText( | ||
| 66 | + applicationContext, | ||
| 67 | + "Please input a positive number for speech speed!", | ||
| 68 | + Toast.LENGTH_SHORT | ||
| 69 | + ).show() | ||
| 70 | + return | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + val textStr = text.text.toString().trim() | ||
| 74 | + if (textStr.isBlank() || textStr.isEmpty()) { | ||
| 75 | + Toast.makeText(applicationContext, "Please input a non-empty text!", Toast.LENGTH_SHORT) | ||
| 76 | + .show() | ||
| 77 | + return | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + Toast.makeText(applicationContext, "Generating...Please wait", Toast.LENGTH_LONG).show() | ||
| 81 | + val audio = tts.generate(text = textStr, sid = sidInt, speed = speedFloat) | ||
| 82 | + | ||
| 83 | + val filename = application.filesDir.absolutePath + "/generated.wav" | ||
| 84 | + val ok = audio.samples.size > 0 && audio.save(filename) | ||
| 85 | + if (ok) { | ||
| 86 | + play.isEnabled = true | ||
| 87 | + Toast.makeText( | ||
| 88 | + applicationContext, | ||
| 89 | + "Generated! Please click play to listen to it", | ||
| 90 | + Toast.LENGTH_LONG | ||
| 91 | + ).show() | ||
| 92 | + } else { | ||
| 93 | + play.isEnabled = false | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + fun onClickPlay() { | ||
| 98 | + val filename = application.filesDir.absolutePath + "/generated.wav" | ||
| 99 | + val mediaPlayer = MediaPlayer.create( | ||
| 100 | + applicationContext, | ||
| 101 | + Uri.fromFile(File(filename)) | ||
| 102 | + ) | ||
| 103 | + mediaPlayer.start() | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + fun initTts() { | ||
| 107 | + // 0 - vits-vctk (multi-speaker, English) | ||
| 108 | + // 1 - vits-zh-aishell3 (multi-speaker, Chinese) | ||
| 109 | + val type = 0 | ||
| 110 | + val config = getOfflineTtsConfig(type = type, debug = true)!! | ||
| 111 | + tts = OfflineTts(assetManager = application.assets, config = config) | ||
| 112 | + } | ||
| 113 | +} |
| @@ -24,10 +24,11 @@ data class OfflineTtsConfig( | @@ -24,10 +24,11 @@ data class OfflineTtsConfig( | ||
| 24 | ) | 24 | ) |
| 25 | 25 | ||
| 26 | class GeneratedAudio( | 26 | class GeneratedAudio( |
| 27 | - val samples : FloatArray, | 27 | + val samples: FloatArray, |
| 28 | val sampleRate: Int, | 28 | val sampleRate: Int, |
| 29 | ) { | 29 | ) { |
| 30 | - fun save(filename: String) = saveImpl(filename=filename, samples=samples, sampleRate=sampleRate) | 30 | + fun save(filename: String) = |
| 31 | + saveImpl(filename = filename, samples = samples, sampleRate = sampleRate) | ||
| 31 | 32 | ||
| 32 | private external fun saveImpl( | 33 | private external fun saveImpl( |
| 33 | filename: String, | 34 | filename: String, |
| @@ -55,26 +56,28 @@ class OfflineTts( | @@ -55,26 +56,28 @@ class OfflineTts( | ||
| 55 | sid: Int = 0, | 56 | sid: Int = 0, |
| 56 | speed: Float = 1.0f | 57 | speed: Float = 1.0f |
| 57 | ): GeneratedAudio { | 58 | ): GeneratedAudio { |
| 58 | - var objArray = generateImpl(ptr, text=text, sid=sid, speed=speed) | ||
| 59 | - return GeneratedAudio(samples=objArray[0] as FloatArray, | ||
| 60 | - sampleRate=objArray[1] as Int) | 59 | + var objArray = generateImpl(ptr, text = text, sid = sid, speed = speed) |
| 60 | + return GeneratedAudio( | ||
| 61 | + samples = objArray[0] as FloatArray, | ||
| 62 | + sampleRate = objArray[1] as Int | ||
| 63 | + ) | ||
| 61 | } | 64 | } |
| 62 | 65 | ||
| 63 | fun allocate(assetManager: AssetManager? = null) { | 66 | fun allocate(assetManager: AssetManager? = null) { |
| 64 | - if (ptr == 0L) { | ||
| 65 | - if (assetManager != null) { | ||
| 66 | - ptr = new(assetManager, config) | ||
| 67 | - } else { | ||
| 68 | - ptr = newFromFile(config) | 67 | + if (ptr == 0L) { |
| 68 | + if (assetManager != null) { | ||
| 69 | + ptr = new(assetManager, config) | ||
| 70 | + } else { | ||
| 71 | + ptr = newFromFile(config) | ||
| 72 | + } | ||
| 69 | } | 73 | } |
| 70 | - } | ||
| 71 | } | 74 | } |
| 72 | 75 | ||
| 73 | fun free() { | 76 | fun free() { |
| 74 | - if (ptr != 0L) { | ||
| 75 | - delete(ptr) | ||
| 76 | - ptr = 0 | ||
| 77 | - } | 77 | + if (ptr != 0L) { |
| 78 | + delete(ptr) | ||
| 79 | + ptr = 0 | ||
| 80 | + } | ||
| 78 | } | 81 | } |
| 79 | 82 | ||
| 80 | protected fun finalize() { | 83 | protected fun finalize() { |
| @@ -108,5 +111,50 @@ class OfflineTts( | @@ -108,5 +111,50 @@ class OfflineTts( | ||
| 108 | System.loadLibrary("sherpa-onnx-jni") | 111 | System.loadLibrary("sherpa-onnx-jni") |
| 109 | } | 112 | } |
| 110 | } | 113 | } |
| 114 | +} | ||
| 115 | + | ||
| 116 | +// please refer to | ||
| 117 | +// https://k2-fsa.github.io/sherpa/onnx/tts/pretrained_models/index.html | ||
| 118 | +// to download models | ||
| 119 | +// | ||
| 120 | +// You can change the type as you wish | ||
| 121 | +fun getOfflineTtsConfig(type: Int, debug: Boolean = false): OfflineTtsConfig? { | ||
| 122 | + when (type) { | ||
| 123 | + 0 -> { | ||
| 124 | + val modelDir = "vits-vctk" | ||
| 125 | + return OfflineTtsConfig( | ||
| 126 | + model = OfflineTtsModelConfig( | ||
| 127 | + vits = OfflineTtsVitsModelConfig( | ||
| 128 | + model = "$modelDir/vits-vctk.onnx", | ||
| 129 | + lexicon = "$modelDir/lexicon.txt", | ||
| 130 | + tokens = "$modelDir/tokens.txt" | ||
| 131 | + ), | ||
| 132 | + numThreads = 2, | ||
| 133 | + debug = debug, | ||
| 134 | + provider = "cpu", | ||
| 135 | + ) | ||
| 136 | + ) | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + 1 -> { | ||
| 140 | + val modelDir = "vits-zh-aishell3" | ||
| 141 | + return OfflineTtsConfig( | ||
| 142 | + model = OfflineTtsModelConfig( | ||
| 143 | + vits = OfflineTtsVitsModelConfig( | ||
| 144 | + model = "$modelDir/vits-aishell3.onnx", | ||
| 145 | + lexicon = "$modelDir/lexicon.txt", | ||
| 146 | + tokens = "$modelDir/tokens.txt" | ||
| 147 | + ), | ||
| 148 | + numThreads = 2, | ||
| 149 | + debug = debug, | ||
| 150 | + provider = "cpu", | ||
| 151 | + ) | ||
| 152 | + ) | ||
| 153 | + } | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + println("Unsupported type $type") | ||
| 157 | + | ||
| 158 | + return null | ||
| 111 | 159 | ||
| 112 | } | 160 | } |
| 1 | +<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 2 | + xmlns:aapt="http://schemas.android.com/aapt" | ||
| 3 | + android:width="108dp" | ||
| 4 | + android:height="108dp" | ||
| 5 | + android:viewportWidth="108" | ||
| 6 | + android:viewportHeight="108"> | ||
| 7 | + <path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z"> | ||
| 8 | + <aapt:attr name="android:fillColor"> | ||
| 9 | + <gradient | ||
| 10 | + android:endX="85.84757" | ||
| 11 | + android:endY="92.4963" | ||
| 12 | + android:startX="42.9492" | ||
| 13 | + android:startY="49.59793" | ||
| 14 | + android:type="linear"> | ||
| 15 | + <item | ||
| 16 | + android:color="#44000000" | ||
| 17 | + android:offset="0.0" /> | ||
| 18 | + <item | ||
| 19 | + android:color="#00000000" | ||
| 20 | + android:offset="1.0" /> | ||
| 21 | + </gradient> | ||
| 22 | + </aapt:attr> | ||
| 23 | + </path> | ||
| 24 | + <path | ||
| 25 | + android:fillColor="#FFFFFF" | ||
| 26 | + android:fillType="nonZero" | ||
| 27 | + android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z" | ||
| 28 | + android:strokeWidth="1" | ||
| 29 | + android:strokeColor="#00000000" /> | ||
| 30 | +</vector> |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | + android:width="108dp" | ||
| 4 | + android:height="108dp" | ||
| 5 | + android:viewportWidth="108" | ||
| 6 | + android:viewportHeight="108"> | ||
| 7 | + <path | ||
| 8 | + android:fillColor="#3DDC84" | ||
| 9 | + android:pathData="M0,0h108v108h-108z" /> | ||
| 10 | + <path | ||
| 11 | + android:fillColor="#00000000" | ||
| 12 | + android:pathData="M9,0L9,108" | ||
| 13 | + android:strokeWidth="0.8" | ||
| 14 | + android:strokeColor="#33FFFFFF" /> | ||
| 15 | + <path | ||
| 16 | + android:fillColor="#00000000" | ||
| 17 | + android:pathData="M19,0L19,108" | ||
| 18 | + android:strokeWidth="0.8" | ||
| 19 | + android:strokeColor="#33FFFFFF" /> | ||
| 20 | + <path | ||
| 21 | + android:fillColor="#00000000" | ||
| 22 | + android:pathData="M29,0L29,108" | ||
| 23 | + android:strokeWidth="0.8" | ||
| 24 | + android:strokeColor="#33FFFFFF" /> | ||
| 25 | + <path | ||
| 26 | + android:fillColor="#00000000" | ||
| 27 | + android:pathData="M39,0L39,108" | ||
| 28 | + android:strokeWidth="0.8" | ||
| 29 | + android:strokeColor="#33FFFFFF" /> | ||
| 30 | + <path | ||
| 31 | + android:fillColor="#00000000" | ||
| 32 | + android:pathData="M49,0L49,108" | ||
| 33 | + android:strokeWidth="0.8" | ||
| 34 | + android:strokeColor="#33FFFFFF" /> | ||
| 35 | + <path | ||
| 36 | + android:fillColor="#00000000" | ||
| 37 | + android:pathData="M59,0L59,108" | ||
| 38 | + android:strokeWidth="0.8" | ||
| 39 | + android:strokeColor="#33FFFFFF" /> | ||
| 40 | + <path | ||
| 41 | + android:fillColor="#00000000" | ||
| 42 | + android:pathData="M69,0L69,108" | ||
| 43 | + android:strokeWidth="0.8" | ||
| 44 | + android:strokeColor="#33FFFFFF" /> | ||
| 45 | + <path | ||
| 46 | + android:fillColor="#00000000" | ||
| 47 | + android:pathData="M79,0L79,108" | ||
| 48 | + android:strokeWidth="0.8" | ||
| 49 | + android:strokeColor="#33FFFFFF" /> | ||
| 50 | + <path | ||
| 51 | + android:fillColor="#00000000" | ||
| 52 | + android:pathData="M89,0L89,108" | ||
| 53 | + android:strokeWidth="0.8" | ||
| 54 | + android:strokeColor="#33FFFFFF" /> | ||
| 55 | + <path | ||
| 56 | + android:fillColor="#00000000" | ||
| 57 | + android:pathData="M99,0L99,108" | ||
| 58 | + android:strokeWidth="0.8" | ||
| 59 | + android:strokeColor="#33FFFFFF" /> | ||
| 60 | + <path | ||
| 61 | + android:fillColor="#00000000" | ||
| 62 | + android:pathData="M0,9L108,9" | ||
| 63 | + android:strokeWidth="0.8" | ||
| 64 | + android:strokeColor="#33FFFFFF" /> | ||
| 65 | + <path | ||
| 66 | + android:fillColor="#00000000" | ||
| 67 | + android:pathData="M0,19L108,19" | ||
| 68 | + android:strokeWidth="0.8" | ||
| 69 | + android:strokeColor="#33FFFFFF" /> | ||
| 70 | + <path | ||
| 71 | + android:fillColor="#00000000" | ||
| 72 | + android:pathData="M0,29L108,29" | ||
| 73 | + android:strokeWidth="0.8" | ||
| 74 | + android:strokeColor="#33FFFFFF" /> | ||
| 75 | + <path | ||
| 76 | + android:fillColor="#00000000" | ||
| 77 | + android:pathData="M0,39L108,39" | ||
| 78 | + android:strokeWidth="0.8" | ||
| 79 | + android:strokeColor="#33FFFFFF" /> | ||
| 80 | + <path | ||
| 81 | + android:fillColor="#00000000" | ||
| 82 | + android:pathData="M0,49L108,49" | ||
| 83 | + android:strokeWidth="0.8" | ||
| 84 | + android:strokeColor="#33FFFFFF" /> | ||
| 85 | + <path | ||
| 86 | + android:fillColor="#00000000" | ||
| 87 | + android:pathData="M0,59L108,59" | ||
| 88 | + android:strokeWidth="0.8" | ||
| 89 | + android:strokeColor="#33FFFFFF" /> | ||
| 90 | + <path | ||
| 91 | + android:fillColor="#00000000" | ||
| 92 | + android:pathData="M0,69L108,69" | ||
| 93 | + android:strokeWidth="0.8" | ||
| 94 | + android:strokeColor="#33FFFFFF" /> | ||
| 95 | + <path | ||
| 96 | + android:fillColor="#00000000" | ||
| 97 | + android:pathData="M0,79L108,79" | ||
| 98 | + android:strokeWidth="0.8" | ||
| 99 | + android:strokeColor="#33FFFFFF" /> | ||
| 100 | + <path | ||
| 101 | + android:fillColor="#00000000" | ||
| 102 | + android:pathData="M0,89L108,89" | ||
| 103 | + android:strokeWidth="0.8" | ||
| 104 | + android:strokeColor="#33FFFFFF" /> | ||
| 105 | + <path | ||
| 106 | + android:fillColor="#00000000" | ||
| 107 | + android:pathData="M0,99L108,99" | ||
| 108 | + android:strokeWidth="0.8" | ||
| 109 | + android:strokeColor="#33FFFFFF" /> | ||
| 110 | + <path | ||
| 111 | + android:fillColor="#00000000" | ||
| 112 | + android:pathData="M19,29L89,29" | ||
| 113 | + android:strokeWidth="0.8" | ||
| 114 | + android:strokeColor="#33FFFFFF" /> | ||
| 115 | + <path | ||
| 116 | + android:fillColor="#00000000" | ||
| 117 | + android:pathData="M19,39L89,39" | ||
| 118 | + android:strokeWidth="0.8" | ||
| 119 | + android:strokeColor="#33FFFFFF" /> | ||
| 120 | + <path | ||
| 121 | + android:fillColor="#00000000" | ||
| 122 | + android:pathData="M19,49L89,49" | ||
| 123 | + android:strokeWidth="0.8" | ||
| 124 | + android:strokeColor="#33FFFFFF" /> | ||
| 125 | + <path | ||
| 126 | + android:fillColor="#00000000" | ||
| 127 | + android:pathData="M19,59L89,59" | ||
| 128 | + android:strokeWidth="0.8" | ||
| 129 | + android:strokeColor="#33FFFFFF" /> | ||
| 130 | + <path | ||
| 131 | + android:fillColor="#00000000" | ||
| 132 | + android:pathData="M19,69L89,69" | ||
| 133 | + android:strokeWidth="0.8" | ||
| 134 | + android:strokeColor="#33FFFFFF" /> | ||
| 135 | + <path | ||
| 136 | + android:fillColor="#00000000" | ||
| 137 | + android:pathData="M19,79L89,79" | ||
| 138 | + android:strokeWidth="0.8" | ||
| 139 | + android:strokeColor="#33FFFFFF" /> | ||
| 140 | + <path | ||
| 141 | + android:fillColor="#00000000" | ||
| 142 | + android:pathData="M29,19L29,89" | ||
| 143 | + android:strokeWidth="0.8" | ||
| 144 | + android:strokeColor="#33FFFFFF" /> | ||
| 145 | + <path | ||
| 146 | + android:fillColor="#00000000" | ||
| 147 | + android:pathData="M39,19L39,89" | ||
| 148 | + android:strokeWidth="0.8" | ||
| 149 | + android:strokeColor="#33FFFFFF" /> | ||
| 150 | + <path | ||
| 151 | + android:fillColor="#00000000" | ||
| 152 | + android:pathData="M49,19L49,89" | ||
| 153 | + android:strokeWidth="0.8" | ||
| 154 | + android:strokeColor="#33FFFFFF" /> | ||
| 155 | + <path | ||
| 156 | + android:fillColor="#00000000" | ||
| 157 | + android:pathData="M59,19L59,89" | ||
| 158 | + android:strokeWidth="0.8" | ||
| 159 | + android:strokeColor="#33FFFFFF" /> | ||
| 160 | + <path | ||
| 161 | + android:fillColor="#00000000" | ||
| 162 | + android:pathData="M69,19L69,89" | ||
| 163 | + android:strokeWidth="0.8" | ||
| 164 | + android:strokeColor="#33FFFFFF" /> | ||
| 165 | + <path | ||
| 166 | + android:fillColor="#00000000" | ||
| 167 | + android:pathData="M79,19L79,89" | ||
| 168 | + android:strokeWidth="0.8" | ||
| 169 | + android:strokeColor="#33FFFFFF" /> | ||
| 170 | +</vector> |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | + xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| 4 | + xmlns:tools="http://schemas.android.com/tools" | ||
| 5 | + android:layout_width="match_parent" | ||
| 6 | + android:layout_height="match_parent" | ||
| 7 | + tools:context=".MainActivity"> | ||
| 8 | + | ||
| 9 | + <TextView | ||
| 10 | + android:id="@+id/sid_label_hint" | ||
| 11 | + android:layout_width="match_parent" | ||
| 12 | + android:layout_height="wrap_content" | ||
| 13 | + android:text="@string/sid_label" | ||
| 14 | + android:gravity="center" | ||
| 15 | + app:layout_constraintLeft_toLeftOf="parent" | ||
| 16 | + app:layout_constraintRight_toRightOf="parent" | ||
| 17 | + app:layout_constraintTop_toTopOf="parent" | ||
| 18 | + /> | ||
| 19 | + <EditText | ||
| 20 | + android:id="@+id/sid" | ||
| 21 | + android:layout_width="match_parent" | ||
| 22 | + android:layout_height="60dp" | ||
| 23 | + android:layout_marginTop="0dp" | ||
| 24 | + android:hint="@string/sid_hint" | ||
| 25 | + android:gravity="center" | ||
| 26 | + app:layout_constraintLeft_toLeftOf="parent" | ||
| 27 | + app:layout_constraintRight_toRightOf="parent" | ||
| 28 | + app:layout_constraintTop_toBottomOf="@id/sid_label_hint" /> | ||
| 29 | + | ||
| 30 | + <TextView | ||
| 31 | + android:id="@+id/speed_label_hint" | ||
| 32 | + android:layout_width="match_parent" | ||
| 33 | + android:layout_height="wrap_content" | ||
| 34 | + android:layout_marginTop="3dp" | ||
| 35 | + android:text="@string/speed_label" | ||
| 36 | + android:gravity="center" | ||
| 37 | + app:layout_constraintLeft_toLeftOf="parent" | ||
| 38 | + app:layout_constraintRight_toRightOf="parent" | ||
| 39 | + app:layout_constraintTop_toBottomOf="@id/sid"/> | ||
| 40 | + <EditText | ||
| 41 | + android:id="@+id/speed" | ||
| 42 | + android:layout_width="match_parent" | ||
| 43 | + android:layout_height="60dp" | ||
| 44 | + android:layout_marginTop="0dp" | ||
| 45 | + android:hint="@string/speed_hint" | ||
| 46 | + android:gravity="center" | ||
| 47 | + app:layout_constraintLeft_toLeftOf="parent" | ||
| 48 | + app:layout_constraintRight_toRightOf="parent" | ||
| 49 | + app:layout_constraintTop_toBottomOf="@id/speed_label_hint" /> | ||
| 50 | + | ||
| 51 | + <EditText | ||
| 52 | + android:id="@+id/text" | ||
| 53 | + android:inputType="textMultiLine" | ||
| 54 | + android:lines="8" | ||
| 55 | + android:minLines="10" | ||
| 56 | + android:gravity="top|start" | ||
| 57 | + android:maxLines="30" | ||
| 58 | + android:layout_height="wrap_content" | ||
| 59 | + android:layout_width="match_parent" | ||
| 60 | + android:scrollbars="vertical" | ||
| 61 | + android:hint="@string/text_hint" | ||
| 62 | + app:layout_constraintLeft_toLeftOf="parent" | ||
| 63 | + app:layout_constraintRight_toRightOf="parent" | ||
| 64 | + app:layout_constraintTop_toBottomOf="@id/speed" /> | ||
| 65 | + | ||
| 66 | + <Button | ||
| 67 | + android:id="@+id/generate" | ||
| 68 | + android:textAllCaps="false" | ||
| 69 | + android:layout_width="match_parent" | ||
| 70 | + android:layout_height="50dp" | ||
| 71 | + android:layout_marginTop="4dp" | ||
| 72 | + android:text="@string/generate" | ||
| 73 | + app:layout_constraintLeft_toLeftOf="parent" | ||
| 74 | + app:layout_constraintRight_toRightOf="parent" | ||
| 75 | + app:layout_constraintTop_toBottomOf="@id/text" /> | ||
| 76 | + | ||
| 77 | + <Button | ||
| 78 | + android:id="@+id/play" | ||
| 79 | + android:textAllCaps="false" | ||
| 80 | + android:layout_width="match_parent" | ||
| 81 | + android:layout_height="50dp" | ||
| 82 | + android:layout_marginTop="4dp" | ||
| 83 | + android:text="@string/play" | ||
| 84 | + app:layout_constraintLeft_toLeftOf="parent" | ||
| 85 | + app:layout_constraintRight_toRightOf="parent" | ||
| 86 | + app:layout_constraintTop_toBottomOf="@id/generate" /> | ||
| 87 | +</androidx.constraintlayout.widget.ConstraintLayout> |
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
| 1 | +<resources xmlns:tools="http://schemas.android.com/tools"> | ||
| 2 | + <!-- Base application theme. --> | ||
| 3 | + <style name="Theme.SherpaOnnxTts" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> | ||
| 4 | + <!-- Primary brand color. --> | ||
| 5 | + <item name="colorPrimary">@color/purple_200</item> | ||
| 6 | + <item name="colorPrimaryVariant">@color/purple_700</item> | ||
| 7 | + <item name="colorOnPrimary">@color/black</item> | ||
| 8 | + <!-- Secondary brand color. --> | ||
| 9 | + <item name="colorSecondary">@color/teal_200</item> | ||
| 10 | + <item name="colorSecondaryVariant">@color/teal_200</item> | ||
| 11 | + <item name="colorOnSecondary">@color/black</item> | ||
| 12 | + <!-- Status bar color. --> | ||
| 13 | + <item name="android:statusBarColor">?attr/colorPrimaryVariant</item> | ||
| 14 | + <!-- Customize your theme here. --> | ||
| 15 | + </style> | ||
| 16 | +</resources> |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<resources> | ||
| 3 | + <color name="purple_200">#FFBB86FC</color> | ||
| 4 | + <color name="purple_500">#FF6200EE</color> | ||
| 5 | + <color name="purple_700">#FF3700B3</color> | ||
| 6 | + <color name="teal_200">#FF03DAC5</color> | ||
| 7 | + <color name="teal_700">#FF018786</color> | ||
| 8 | + <color name="black">#FF000000</color> | ||
| 9 | + <color name="white">#FFFFFFFF</color> | ||
| 10 | +</resources> |
| 1 | +<resources> | ||
| 2 | + <string name="app_name">Next-gen Kaldi: TTS</string> | ||
| 3 | + <string name="sid_label">Speaker ID</string> | ||
| 4 | + <string name="sid_hint">0</string> | ||
| 5 | + <string name="speed_label">Speech speed (large->fast)</string> | ||
| 6 | + <string name="speed_hint">1.0</string> | ||
| 7 | + <string name="text_hint">Please input your text here</string> | ||
| 8 | + <string name="generate">Generate</string> | ||
| 9 | + <string name="play">Play</string> | ||
| 10 | +</resources> |
| 1 | +<resources xmlns:tools="http://schemas.android.com/tools"> | ||
| 2 | + <!-- Base application theme. --> | ||
| 3 | + <style name="Theme.SherpaOnnxTts" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> | ||
| 4 | + <!-- Primary brand color. --> | ||
| 5 | + <item name="colorPrimary">@color/purple_500</item> | ||
| 6 | + <item name="colorPrimaryVariant">@color/purple_700</item> | ||
| 7 | + <item name="colorOnPrimary">@color/white</item> | ||
| 8 | + <!-- Secondary brand color. --> | ||
| 9 | + <item name="colorSecondary">@color/teal_200</item> | ||
| 10 | + <item name="colorSecondaryVariant">@color/teal_700</item> | ||
| 11 | + <item name="colorOnSecondary">@color/black</item> | ||
| 12 | + <!-- Status bar color. --> | ||
| 13 | + <item name="android:statusBarColor">?attr/colorPrimaryVariant</item> | ||
| 14 | + <!-- Customize your theme here. --> | ||
| 15 | + </style> | ||
| 16 | +</resources> |
| 1 | +<?xml version="1.0" encoding="utf-8"?><!-- | ||
| 2 | + Sample backup rules file; uncomment and customize as necessary. | ||
| 3 | + See https://developer.android.com/guide/topics/data/autobackup | ||
| 4 | + for details. | ||
| 5 | + Note: This file is ignored for devices older that API 31 | ||
| 6 | + See https://developer.android.com/about/versions/12/backup-restore | ||
| 7 | +--> | ||
| 8 | +<full-backup-content> | ||
| 9 | + <!-- | ||
| 10 | + <include domain="sharedpref" path="."/> | ||
| 11 | + <exclude domain="sharedpref" path="device.xml"/> | ||
| 12 | +--> | ||
| 13 | +</full-backup-content> |
| 1 | +<?xml version="1.0" encoding="utf-8"?><!-- | ||
| 2 | + Sample data extraction rules file; uncomment and customize as necessary. | ||
| 3 | + See https://developer.android.com/about/versions/12/backup-restore#xml-changes | ||
| 4 | + for details. | ||
| 5 | +--> | ||
| 6 | +<data-extraction-rules> | ||
| 7 | + <cloud-backup> | ||
| 8 | + <!-- TODO: Use <include> and <exclude> to control what is backed up. | ||
| 9 | + <include .../> | ||
| 10 | + <exclude .../> | ||
| 11 | + --> | ||
| 12 | + </cloud-backup> | ||
| 13 | + <!-- | ||
| 14 | + <device-transfer> | ||
| 15 | + <include .../> | ||
| 16 | + <exclude .../> | ||
| 17 | + </device-transfer> | ||
| 18 | + --> | ||
| 19 | +</data-extraction-rules> |
| 1 | +package com.k2fsa.sherpa.onnx | ||
| 2 | + | ||
| 3 | +import org.junit.Test | ||
| 4 | + | ||
| 5 | +import org.junit.Assert.* | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * Example local unit test, which will execute on the development machine (host). | ||
| 9 | + * | ||
| 10 | + * See [testing documentation](http://d.android.com/tools/testing). | ||
| 11 | + */ | ||
| 12 | +class ExampleUnitTest { | ||
| 13 | + @Test | ||
| 14 | + fun addition_isCorrect() { | ||
| 15 | + assertEquals(4, 2 + 2) | ||
| 16 | + } | ||
| 17 | +} |
android/SherpaOnnxTts/build.gradle
0 → 100644
| 1 | +// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
| 2 | +plugins { | ||
| 3 | + id 'com.android.application' version '7.3.1' apply false | ||
| 4 | + id 'com.android.library' version '7.3.1' apply false | ||
| 5 | + id 'org.jetbrains.kotlin.android' version '1.7.20' apply false | ||
| 6 | +} |
android/SherpaOnnxTts/gradle.properties
0 → 100644
| 1 | +# Project-wide Gradle settings. | ||
| 2 | +# IDE (e.g. Android Studio) users: | ||
| 3 | +# Gradle settings configured through the IDE *will override* | ||
| 4 | +# any settings specified in this file. | ||
| 5 | +# For more details on how to configure your build environment visit | ||
| 6 | +# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
| 7 | +# Specifies the JVM arguments used for the daemon process. | ||
| 8 | +# The setting is particularly useful for tweaking memory settings. | ||
| 9 | +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 | ||
| 10 | +# When configured, Gradle will run in incubating parallel mode. | ||
| 11 | +# This option should only be used with decoupled projects. More details, visit | ||
| 12 | +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||
| 13 | +# org.gradle.parallel=true | ||
| 14 | +# AndroidX package structure to make it clearer which packages are bundled with the | ||
| 15 | +# Android operating system, and which are packaged with your app's APK | ||
| 16 | +# https://developer.android.com/topic/libraries/support-library/androidx-rn | ||
| 17 | +android.useAndroidX=true | ||
| 18 | +# Kotlin code style for this project: "official" or "obsolete": | ||
| 19 | +kotlin.code.style=official | ||
| 20 | +# Enables namespacing of each library's R class so that its R class includes only the | ||
| 21 | +# resources declared in the library itself and none from the library's dependencies, | ||
| 22 | +# thereby reducing the size of the R class for that library | ||
| 23 | +android.nonTransitiveRClass=true |
不能预览此文件类型
android/SherpaOnnxTts/gradlew
0 → 100755
| 1 | +#!/usr/bin/env sh | ||
| 2 | + | ||
| 3 | +# | ||
| 4 | +# Copyright 2015 the original author or authors. | ||
| 5 | +# | ||
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 7 | +# you may not use this file except in compliance with the License. | ||
| 8 | +# You may obtain a copy of the License at | ||
| 9 | +# | ||
| 10 | +# https://www.apache.org/licenses/LICENSE-2.0 | ||
| 11 | +# | ||
| 12 | +# Unless required by applicable law or agreed to in writing, software | ||
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 15 | +# See the License for the specific language governing permissions and | ||
| 16 | +# limitations under the License. | ||
| 17 | +# | ||
| 18 | + | ||
| 19 | +############################################################################## | ||
| 20 | +## | ||
| 21 | +## Gradle start up script for UN*X | ||
| 22 | +## | ||
| 23 | +############################################################################## | ||
| 24 | + | ||
| 25 | +# Attempt to set APP_HOME | ||
| 26 | +# Resolve links: $0 may be a link | ||
| 27 | +PRG="$0" | ||
| 28 | +# Need this for relative symlinks. | ||
| 29 | +while [ -h "$PRG" ] ; do | ||
| 30 | + ls=`ls -ld "$PRG"` | ||
| 31 | + link=`expr "$ls" : '.*-> \(.*\)$'` | ||
| 32 | + if expr "$link" : '/.*' > /dev/null; then | ||
| 33 | + PRG="$link" | ||
| 34 | + else | ||
| 35 | + PRG=`dirname "$PRG"`"/$link" | ||
| 36 | + fi | ||
| 37 | +done | ||
| 38 | +SAVED="`pwd`" | ||
| 39 | +cd "`dirname \"$PRG\"`/" >/dev/null | ||
| 40 | +APP_HOME="`pwd -P`" | ||
| 41 | +cd "$SAVED" >/dev/null | ||
| 42 | + | ||
| 43 | +APP_NAME="Gradle" | ||
| 44 | +APP_BASE_NAME=`basename "$0"` | ||
| 45 | + | ||
| 46 | +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | ||
| 47 | +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' | ||
| 48 | + | ||
| 49 | +# Use the maximum available, or set MAX_FD != -1 to use that value. | ||
| 50 | +MAX_FD="maximum" | ||
| 51 | + | ||
| 52 | +warn () { | ||
| 53 | + echo "$*" | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +die () { | ||
| 57 | + echo | ||
| 58 | + echo "$*" | ||
| 59 | + echo | ||
| 60 | + exit 1 | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +# OS specific support (must be 'true' or 'false'). | ||
| 64 | +cygwin=false | ||
| 65 | +msys=false | ||
| 66 | +darwin=false | ||
| 67 | +nonstop=false | ||
| 68 | +case "`uname`" in | ||
| 69 | + CYGWIN* ) | ||
| 70 | + cygwin=true | ||
| 71 | + ;; | ||
| 72 | + Darwin* ) | ||
| 73 | + darwin=true | ||
| 74 | + ;; | ||
| 75 | + MINGW* ) | ||
| 76 | + msys=true | ||
| 77 | + ;; | ||
| 78 | + NONSTOP* ) | ||
| 79 | + nonstop=true | ||
| 80 | + ;; | ||
| 81 | +esac | ||
| 82 | + | ||
| 83 | +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar | ||
| 84 | + | ||
| 85 | + | ||
| 86 | +# Determine the Java command to use to start the JVM. | ||
| 87 | +if [ -n "$JAVA_HOME" ] ; then | ||
| 88 | + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then | ||
| 89 | + # IBM's JDK on AIX uses strange locations for the executables | ||
| 90 | + JAVACMD="$JAVA_HOME/jre/sh/java" | ||
| 91 | + else | ||
| 92 | + JAVACMD="$JAVA_HOME/bin/java" | ||
| 93 | + fi | ||
| 94 | + if [ ! -x "$JAVACMD" ] ; then | ||
| 95 | + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME | ||
| 96 | + | ||
| 97 | +Please set the JAVA_HOME variable in your environment to match the | ||
| 98 | +location of your Java installation." | ||
| 99 | + fi | ||
| 100 | +else | ||
| 101 | + JAVACMD="java" | ||
| 102 | + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | ||
| 103 | + | ||
| 104 | +Please set the JAVA_HOME variable in your environment to match the | ||
| 105 | +location of your Java installation." | ||
| 106 | +fi | ||
| 107 | + | ||
| 108 | +# Increase the maximum file descriptors if we can. | ||
| 109 | +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then | ||
| 110 | + MAX_FD_LIMIT=`ulimit -H -n` | ||
| 111 | + if [ $? -eq 0 ] ; then | ||
| 112 | + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then | ||
| 113 | + MAX_FD="$MAX_FD_LIMIT" | ||
| 114 | + fi | ||
| 115 | + ulimit -n $MAX_FD | ||
| 116 | + if [ $? -ne 0 ] ; then | ||
| 117 | + warn "Could not set maximum file descriptor limit: $MAX_FD" | ||
| 118 | + fi | ||
| 119 | + else | ||
| 120 | + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" | ||
| 121 | + fi | ||
| 122 | +fi | ||
| 123 | + | ||
| 124 | +# For Darwin, add options to specify how the application appears in the dock | ||
| 125 | +if $darwin; then | ||
| 126 | + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" | ||
| 127 | +fi | ||
| 128 | + | ||
| 129 | +# For Cygwin or MSYS, switch paths to Windows format before running java | ||
| 130 | +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then | ||
| 131 | + APP_HOME=`cygpath --path --mixed "$APP_HOME"` | ||
| 132 | + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` | ||
| 133 | + | ||
| 134 | + JAVACMD=`cygpath --unix "$JAVACMD"` | ||
| 135 | + | ||
| 136 | + # We build the pattern for arguments to be converted via cygpath | ||
| 137 | + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` | ||
| 138 | + SEP="" | ||
| 139 | + for dir in $ROOTDIRSRAW ; do | ||
| 140 | + ROOTDIRS="$ROOTDIRS$SEP$dir" | ||
| 141 | + SEP="|" | ||
| 142 | + done | ||
| 143 | + OURCYGPATTERN="(^($ROOTDIRS))" | ||
| 144 | + # Add a user-defined pattern to the cygpath arguments | ||
| 145 | + if [ "$GRADLE_CYGPATTERN" != "" ] ; then | ||
| 146 | + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" | ||
| 147 | + fi | ||
| 148 | + # Now convert the arguments - kludge to limit ourselves to /bin/sh | ||
| 149 | + i=0 | ||
| 150 | + for arg in "$@" ; do | ||
| 151 | + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` | ||
| 152 | + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option | ||
| 153 | + | ||
| 154 | + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition | ||
| 155 | + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` | ||
| 156 | + else | ||
| 157 | + eval `echo args$i`="\"$arg\"" | ||
| 158 | + fi | ||
| 159 | + i=`expr $i + 1` | ||
| 160 | + done | ||
| 161 | + case $i in | ||
| 162 | + 0) set -- ;; | ||
| 163 | + 1) set -- "$args0" ;; | ||
| 164 | + 2) set -- "$args0" "$args1" ;; | ||
| 165 | + 3) set -- "$args0" "$args1" "$args2" ;; | ||
| 166 | + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; | ||
| 167 | + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; | ||
| 168 | + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; | ||
| 169 | + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; | ||
| 170 | + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; | ||
| 171 | + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; | ||
| 172 | + esac | ||
| 173 | +fi | ||
| 174 | + | ||
| 175 | +# Escape application args | ||
| 176 | +save () { | ||
| 177 | + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done | ||
| 178 | + echo " " | ||
| 179 | +} | ||
| 180 | +APP_ARGS=`save "$@"` | ||
| 181 | + | ||
| 182 | +# Collect all arguments for the java command, following the shell quoting and substitution rules | ||
| 183 | +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" | ||
| 184 | + | ||
| 185 | +exec "$JAVACMD" "$@" |
android/SherpaOnnxTts/gradlew.bat
0 → 100644
| 1 | +@rem | ||
| 2 | +@rem Copyright 2015 the original author or authors. | ||
| 3 | +@rem | ||
| 4 | +@rem Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | +@rem you may not use this file except in compliance with the License. | ||
| 6 | +@rem You may obtain a copy of the License at | ||
| 7 | +@rem | ||
| 8 | +@rem https://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | +@rem | ||
| 10 | +@rem Unless required by applicable law or agreed to in writing, software | ||
| 11 | +@rem distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | +@rem See the License for the specific language governing permissions and | ||
| 14 | +@rem limitations under the License. | ||
| 15 | +@rem | ||
| 16 | + | ||
| 17 | +@if "%DEBUG%" == "" @echo off | ||
| 18 | +@rem ########################################################################## | ||
| 19 | +@rem | ||
| 20 | +@rem Gradle startup script for Windows | ||
| 21 | +@rem | ||
| 22 | +@rem ########################################################################## | ||
| 23 | + | ||
| 24 | +@rem Set local scope for the variables with windows NT shell | ||
| 25 | +if "%OS%"=="Windows_NT" setlocal | ||
| 26 | + | ||
| 27 | +set DIRNAME=%~dp0 | ||
| 28 | +if "%DIRNAME%" == "" set DIRNAME=. | ||
| 29 | +set APP_BASE_NAME=%~n0 | ||
| 30 | +set APP_HOME=%DIRNAME% | ||
| 31 | + | ||
| 32 | +@rem Resolve any "." and ".." in APP_HOME to make it shorter. | ||
| 33 | +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi | ||
| 34 | + | ||
| 35 | +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | ||
| 36 | +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" | ||
| 37 | + | ||
| 38 | +@rem Find java.exe | ||
| 39 | +if defined JAVA_HOME goto findJavaFromJavaHome | ||
| 40 | + | ||
| 41 | +set JAVA_EXE=java.exe | ||
| 42 | +%JAVA_EXE% -version >NUL 2>&1 | ||
| 43 | +if "%ERRORLEVEL%" == "0" goto execute | ||
| 44 | + | ||
| 45 | +echo. | ||
| 46 | +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | ||
| 47 | +echo. | ||
| 48 | +echo Please set the JAVA_HOME variable in your environment to match the | ||
| 49 | +echo location of your Java installation. | ||
| 50 | + | ||
| 51 | +goto fail | ||
| 52 | + | ||
| 53 | +:findJavaFromJavaHome | ||
| 54 | +set JAVA_HOME=%JAVA_HOME:"=% | ||
| 55 | +set JAVA_EXE=%JAVA_HOME%/bin/java.exe | ||
| 56 | + | ||
| 57 | +if exist "%JAVA_EXE%" goto execute | ||
| 58 | + | ||
| 59 | +echo. | ||
| 60 | +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% | ||
| 61 | +echo. | ||
| 62 | +echo Please set the JAVA_HOME variable in your environment to match the | ||
| 63 | +echo location of your Java installation. | ||
| 64 | + | ||
| 65 | +goto fail | ||
| 66 | + | ||
| 67 | +:execute | ||
| 68 | +@rem Setup the command line | ||
| 69 | + | ||
| 70 | +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar | ||
| 71 | + | ||
| 72 | + | ||
| 73 | +@rem Execute Gradle | ||
| 74 | +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* | ||
| 75 | + | ||
| 76 | +:end | ||
| 77 | +@rem End local scope for the variables with windows NT shell | ||
| 78 | +if "%ERRORLEVEL%"=="0" goto mainEnd | ||
| 79 | + | ||
| 80 | +:fail | ||
| 81 | +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of | ||
| 82 | +rem the _cmd.exe /c_ return code! | ||
| 83 | +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 | ||
| 84 | +exit /b 1 | ||
| 85 | + | ||
| 86 | +:mainEnd | ||
| 87 | +if "%OS%"=="Windows_NT" endlocal | ||
| 88 | + | ||
| 89 | +:omega |
android/SherpaOnnxTts/settings.gradle
0 → 100644
| 1 | +pluginManagement { | ||
| 2 | + repositories { | ||
| 3 | + gradlePluginPortal() | ||
| 4 | + google() | ||
| 5 | + mavenCentral() | ||
| 6 | + } | ||
| 7 | +} | ||
| 8 | +dependencyResolutionManagement { | ||
| 9 | + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) | ||
| 10 | + repositories { | ||
| 11 | + google() | ||
| 12 | + mavenCentral() | ||
| 13 | + } | ||
| 14 | +} | ||
| 15 | +rootProject.name = "SherpaOnnxTts" | ||
| 16 | +include ':app' |
build-apk-tts.sh
0 → 100755
| 1 | +#!/usr/bin/env bash | ||
| 2 | + | ||
| 3 | +# Please set the environment variable ANDROID_NDK | ||
| 4 | +# before running this script | ||
| 5 | + | ||
| 6 | +# Inside the $ANDROID_NDK directory, you can find a binary ndk-build | ||
| 7 | +# and some other files like the file "build/cmake/android.toolchain.cmake" | ||
| 8 | + | ||
| 9 | +set -e | ||
| 10 | + | ||
| 11 | +log() { | ||
| 12 | + # This function is from espnet | ||
| 13 | + local fname=${BASH_SOURCE[1]##*/} | ||
| 14 | + echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*" | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) | ||
| 18 | + | ||
| 19 | +log "Building APK for sherpa-onnx v${SHERPA_ONNX_VERSION}" | ||
| 20 | + | ||
| 21 | +log "====================arm64-v8a=================" | ||
| 22 | +./build-android-arm64-v8a.sh | ||
| 23 | +log "====================armv7-eabi================" | ||
| 24 | +./build-android-armv7-eabi.sh | ||
| 25 | +log "====================x86-64====================" | ||
| 26 | +./build-android-x86-64.sh | ||
| 27 | +log "====================x86====================" | ||
| 28 | +./build-android-x86.sh | ||
| 29 | + | ||
| 30 | + | ||
| 31 | +mkdir -p apks | ||
| 32 | + | ||
| 33 | +# Download the model | ||
| 34 | +pushd ./android/SherpaOnnxTts/app/src/main/assets/ | ||
| 35 | +mkdir vits-vctk | ||
| 36 | + | ||
| 37 | +cd vits-vctk | ||
| 38 | +wget -qq https://huggingface.co/csukuangfj/vits-vctk/resolve/main/vits-vctk.onnx | ||
| 39 | +wget -qq https://huggingface.co/csukuangfj/vits-vctk/resolve/main/lexicon.txt | ||
| 40 | +wget -qq https://huggingface.co/csukuangfj/vits-vctk/resolve/main/tokens.txt | ||
| 41 | +popd | ||
| 42 | + | ||
| 43 | +for arch in arm64-v8a armeabi-v7a x86_64 x86; do | ||
| 44 | + log "------------------------------------------------------------" | ||
| 45 | + log "build tts apk for $arch" | ||
| 46 | + log "------------------------------------------------------------" | ||
| 47 | + src_arch=$arch | ||
| 48 | + if [ $arch == "armeabi-v7a" ]; then | ||
| 49 | + src_arch=armv7-eabi | ||
| 50 | + elif [ $arch == "x86_64" ]; then | ||
| 51 | + src_arch=x86-64 | ||
| 52 | + fi | ||
| 53 | + | ||
| 54 | + ls -lh ./build-android-$src_arch/install/lib/*.so | ||
| 55 | + | ||
| 56 | + cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnxTts/app/src/main/jniLibs/$arch/ | ||
| 57 | + | ||
| 58 | + pushd ./android/SherpaOnnxTts | ||
| 59 | + ./gradlew build | ||
| 60 | + popd | ||
| 61 | + | ||
| 62 | + mv android/SherpaOnnxTts/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-en-tts-multi-speaker-vctk.apk | ||
| 63 | + ls -lh apks | ||
| 64 | + rm -v ./android/SherpaOnnxTts/app/src/main/jniLibs/$arch/*.so | ||
| 65 | +done | ||
| 66 | + | ||
| 67 | +rm -rf ./android/SherpaOnnxTts/app/src/main/assets/vits-vctk | ||
| 68 | + | ||
| 69 | +git checkout . | ||
| 70 | +pushd android/SherpaOnnxTts/app/src/main/java/com/k2fsa/sherpa/onnx | ||
| 71 | +sed -i.bak s/"type = 0"/"type = 1"/ ./MainActivity.kt | ||
| 72 | +git diff | ||
| 73 | +popd | ||
| 74 | + | ||
| 75 | +pushd ./android/SherpaOnnxTts/app/src/main/assets/ | ||
| 76 | +mkdir vits-zh-aishell3 | ||
| 77 | +cd vits-zh-aishell3 | ||
| 78 | + | ||
| 79 | +wget -qq https://huggingface.co/csukuangfj/vits-zh-aishell3/resolve/main/vits-aishell3.onnx | ||
| 80 | +wget -qq https://huggingface.co/csukuangfj/vits-zh-aishell3/resolve/main/lexicon.txt | ||
| 81 | +wget -qq https://huggingface.co/csukuangfj/vits-zh-aishell3/resolve/main/tokens.txt | ||
| 82 | + | ||
| 83 | +popd | ||
| 84 | + | ||
| 85 | +for arch in arm64-v8a armeabi-v7a x86_64 x86; do | ||
| 86 | + log "------------------------------------------------------------" | ||
| 87 | + log "build tts apk for $arch" | ||
| 88 | + log "------------------------------------------------------------" | ||
| 89 | + src_arch=$arch | ||
| 90 | + if [ $arch == "armeabi-v7a" ]; then | ||
| 91 | + src_arch=armv7-eabi | ||
| 92 | + elif [ $arch == "x86_64" ]; then | ||
| 93 | + src_arch=x86-64 | ||
| 94 | + fi | ||
| 95 | + | ||
| 96 | + ls -lh ./build-android-$src_arch/install/lib/*.so | ||
| 97 | + | ||
| 98 | + cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnxTts/app/src/main/jniLibs/$arch/ | ||
| 99 | + | ||
| 100 | + pushd ./android/SherpaOnnxTts | ||
| 101 | + ./gradlew build | ||
| 102 | + popd | ||
| 103 | + | ||
| 104 | + mv android/SherpaOnnxTts/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-zh-tts-multi-speaker-aishell3.apk | ||
| 105 | + ls -lh apks | ||
| 106 | + rm -v ./android/SherpaOnnxTts/app/src/main/jniLibs/$arch/*.so | ||
| 107 | +done | ||
| 108 | + | ||
| 109 | +rm -rf ./android/SherpaOnnxTts/app/src/main/assets/vits-vctk | ||
| 110 | + | ||
| 111 | +git checkout . | ||
| 112 | + | ||
| 113 | +ls -lh apks/ |
kotlin-api-examples/Tts.kt
0 → 120000
| 1 | +../android/SherpaOnnxTts/app/src/main/java/com/k2fsa/sherpa/onnx/Tts.kt |
-
请 注册 或 登录 后发表评论