badwood316

  重新拾起刚入门的android,开发个小工具,一来不让自己离开发太远,二来看能否做出一个帮助自己管儿子学习的东西。

  这次的主题是语音识别。稍微研究了下,开放的语音识别平台,本地识别的担心识别率问题,在线的平台google不可用,简单起见选择了科大讯飞。首先到科大讯飞的开放平台注册账号,新建个Android应用,下载SDK。相关的介绍这就不说了。只说怎么根据SDK里面的demo进行移植改造。

  1、目前只使用语音识别功能,偷懒,使用demo的两个页面:IatDemo和IatSettings。需要移植这两个页面的xml、java类以及其他string、图片等资源。

  2、需要新建继承Application的类,在OnCreate函数中初始化,否则运行会报错。

SpeechUtility.createUtility(AssistApp.this, "appid=" + getString(R.string.app_id));

  3、需要把libs下的库放到app目录下(与src同级),否则会提示没有正确放置库文件;需要把assets目录放到main下(与res同级),否则会闪退。估计是显示对话框时找不到资源。

  4、需要修改AndroidManifest.xml,增加权限申请,activity。

  5、需要修改模块的build.gradle:

apply plugin: \'com.android.application\'
android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.my.study"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile(\'proguard-android.txt\'), \'proguard-rules.pro\'
        }
    }
    sourceSets {
        main {
            jniLibs.srcDirs = [\'libs\']
        }
    }
    buildToolsVersion \'26.0.2\'
}
dependencies {
    implementation fileTree(include: [\'*.jar\'], dir: \'libs\')
    implementation \'com.android.support:appcompat-v7:26.1.0\'
    implementation \'com.android.support.constraint:constraint-layout:1.0.2\'
    implementation \'com.android.support:design:26.1.0\'
    testImplementation \'junit:junit:4.12\'
    androidTestImplementation \'com.android.support.test:runner:1.0.1\'
    androidTestImplementation \'com.android.support.test.espresso:espresso-core:3.0.1\'
    implementation files(\'libs/Msc.jar\')
    implementation files(\'libs/Sunflower.jar\')
}

  其中第20行很重要,不然会报本地资源错20021。当然倒数第2、3行也很重要。

分类:

技术点:

相关文章:

  • 2021-08-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2021-11-30
  • 2022-12-23
猜你喜欢
  • 2022-01-10
  • 2022-01-11
  • 2021-09-29
相关资源
相似解决方案