语音识别android开源代码(android开发语音)
admin 发布:2022-12-19 02:54 112
本篇文章给大家谈谈语音识别android开源代码,以及android开发语音对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
如何用pocketsphinx实现android离线语音识别
1.搭建Android开发环境和NDK配置就不说了,网上教程很多。
2.下载sphinxbase – snapshot,pocketsphinx – snapshot和PocketsphinxAndroidDemo – snapshot,然后吧sphinxbase和pocketsphinx放到同一个文件夹下,用./autogen.sh ./configure make make install的方法先安装sphinxbase,再安装pocketsphinx。
3.把PocketSphinxDemo导入Eclipse,进入PocketSphinxDemo/jni文件夹,把Android.mk里的SPHINX_PATH变量改成sphinxbase和pocketsphinx的父目录。
4.在jni文件夹运行ndk-build命令。(当然,需要先配置好ndk)
5.在Eclipse里,PocketSphinxDemo项目的Properties中,选择Builders,可以看到SWIG和NDK,NDK的build其实可以通过4中的命令来完成,也可以通过eclipse自动完成。
选择NDK,点击Edit按钮,出现的框中,在Location区域选择ndk文件夹,然后点击Refresh选项卡,选择“The project containing the selected resource”,点击Build Options选项卡,取消选择“Specify working set of relevant resources”。
选择SWIG,点击Edit,在Refresh选项卡中选择 “The folder containing the selected resource”,在Build Options选项卡中取消选择“Specifiy working set of relevant resources”。
6.把手机和电脑连接,把pocketsphinx/model/hmm/en_US里的hub4wsj_sc_8k,hmm/en_US,lm/en_US放入手机的某个文件夹,如用adb push把使手机存在如下文件或文件夹:
/sdcard/Android/data/edu.cmu.pocketsphinx/hmm/en_US/hub4wsj_sc_8k
/sdcard/Android/data/edu.cmu.pocketsphinx/lm/en_US/hub4.5000.dic
/sdcard/Android/data/edu.cmu.pocketsphinx/lm/en_US/hub4.5000.DMP
7.在PocketSphinxDemo项目中使 RecognizerTask.java里c.setString函数中的参数符合6中存放的文件和文件夹。
8.构建运行
Android中如何添加语音识别功能?详细步骤和代码?
android.speech.RecognizerIntent这个包里。前提是你的手机支持此功能。
开启操作:
Intent
intent
=
newIntent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);//开启语音识别功能。
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
//设置语言类型。
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
"请说话,我识别");
startActivityForResult(intent,REQUEST_CODE);
在onActivityResult()里用:
data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)取得google云端反馈的数据即可。
如何在android平台上实现语音识别
语音识别,借助于云端技术可以识别用户的语音输入,包括语音控制等技术,下面我们将利用Google 提供的Api 实现这一功能。
功能点为:通过用户语音将用户输入的语音识别出来,并打印在列表上。
功能界面如下:
步骤阅读
2
用户通过点击speak按钮显示界面:
步骤阅读
3
用户说完话后,将提交到云端搜索
步骤阅读
4
在云端搜索完成后,返回打印数据:
步骤阅读
5
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.apis.app;
import com.example.android.apis.R;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
/**
* Sample code that invokes the speech recognition intent API.
*/
public class VoiceRecognition extends Activity implements OnClickListener {
private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
private ListView mList;
/**
* Called with the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Inflate our UI from its XML layout description.
setContentView(R.layout.voice_recognition);
// Get display items for later interaction
Button speakButton = (Button) findViewById(R.id.btn_speak);
mList = (ListView) findViewById(R.id.list);
// Check to see if a recognition activity is present
PackageManager pm = getPackageManager();
List activities = pm.queryIntentActivities(
new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (activities.size() != 0) {
speakButton.setOnClickListener(this);
} else {
speakButton.setEnabled(false);
speakButton.setText("Recognizer not present");
}
}
/**
* Handle the click on the start recognition button.
*/
public void onClick(View v) {
if (v.getId() == R.id.btn_speak) {
startVoiceRecognitionActivity();
}
}
/**
* Fire an intent to start the speech recognition activity.
*/
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
/**
* Handle the results from the recognition activity.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE resultCode == RESULT_OK) {
// Fill the list view with the strings the recognizer thought it could have heard
ArrayList matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
mList.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1,
matches));
}
super.onActivityResult(requestCode, resultCode, data);
}
关于语音识别android开源代码和android开发语音的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-15免费开发软件制作平台,软件免费开发网站
- 05-13web前端开发工程师,Web前端开发工程师是做什么的
- 05-12小程序定制开发,小程序定制开发需要多少钱
- 05-09网页代码,网页代码快捷键
- 05-06单页网站的代码(完整的网页代码)[20240506更新]
- 05-06个人主页图片代码(个人主页图片代码怎么弄)[20240506更新]
- 05-06提取微信名片代码(微信名片信息提取)[20240506更新]
- 05-06php后台权限管理代码(php管理员权限)[20240506更新]
- 05-06付费观看代码php(付费观看代码)[20240506更新]
- 05-06在线html执行代码(html怎么运行)[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接