我尝试实现 Text To Speech,但是当我编写一个方法时,它没有正确显示语音方法。以下是我的方法代码
主活动.java
private void ConvertTextToSpeech() {
// TODO Auto-generated method stub
text = et.getText().toString();
// If no text is typed, tts will read out 'You haven't typed text'
// else it reads out the text you typed
if (text.length() == 0) {
tts.speak("You haven't typed text", TextToSpeech.QUEUE_FLUSH, null);
} else {
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
不是像上面那样显示,而是像这样显示
tts.s̶p̶e̶a̶k̶
我的 build.gradle(app) 是
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.example.Hacker.texttospeech"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
如何使它工作?我认为这是一个API问题。
我正在尝试在 API 级别 16 上实现这一点。
如果是 API 问题,如何在 API 级别 16+ 上运行它?
只需检查文档以获取正确的表格
此方法在 API 级别 21 中已弃用。
从 API 级别 21 开始,替换为
speak(CharSequence, int, Bundle, String)
如果这不起作用,那么问题出在其他地方
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句