zoukankan      html  css  js  c++  java
  • 再战android-语音识别1(科大讯飞)

      重新拾起刚入门的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行也很重要。

  • 相关阅读:
    第二阶段~JS中的各种循环语句
    项目一~达人美食图册详情
    项目一~达人行程
    项目一~美食达人图册
    项目一~机票2
    项目一~达人首页
    项目一~Hotel5
    pythonday02基础与运算符
    pythonday01计算机初步认识
    第六章 百度Apollo ROS介绍(2)
  • 原文地址:https://www.cnblogs.com/badwood316/p/7881879.html
Copyright © 2011-2022 走看看