文字转语音:语音方法不起作用
Text To Speech: speech method is not working
我尝试实现文本转语音,但是当我编写一个方法时,它没有正确显示语音方法。以下是我的方法代码
MainActivity.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+ 上 运行 它?
只需检查文档以获得正确的形式
This method was deprecated in API level 21.
As of API level 21, replaced by speak(CharSequence, int, Bundle, String)
如果这不起作用,则问题出在其他地方
我尝试实现文本转语音,但是当我编写一个方法时,它没有正确显示语音方法。以下是我的方法代码
MainActivity.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+ 上 运行 它?
只需检查文档以获得正确的形式
This method was deprecated in API level 21.
As of API level 21, replaced by
speak(CharSequence, int, Bundle, String)
如果这不起作用,则问题出在其他地方