我做了很多研究并尝试了离线袖珍狮身人面像,但它正在接受周围的声音,并对我的应用做出不同的 react 。是否有适用于 kitkat 4.4 以上的任何 Google 离线应用程序..我从 2 周开始尝试。感谢您宝贵的回答。
详细信息:当 Activity 开始时,第一个文本必须在完成后阅读内容(文本到语音),阅读语音识别必须采用语音并根据命令 ex:(下一个,上一个,前向、选项、1、2、3、4 等)。根据命令,它必须在 onresult 方法中识别并对其使用react。
错误:获取一些声音后出现错误
06-18 19:54:00.159: V/onBeginningOfSpeech(3360): onBeginningOfSpeech
06-18 19:54:01.024: V/onPartialResult(3360): option
06-18 19:54:01.109: I/cmusphinx(3360): INFO: fsg_search.c(843): 105 frames, 5333 HMMs (50/fr), 7748 senones (73/fr), 371 history entries (3/fr)
06-18 19:54:01.110: I/SpeechRecognizer(3360): Stop recognition
06-18 19:54:01.110: E/cmusphinx(3360): ERROR: "fsg_search.c", line 913: Final result does not match the grammar in frame 105
06-18 19:54:01.111: V/onPartialResult-->(3360): option
06-18 19:54:01.111: V/onResult(3360): onResult
但如果我关闭互联网,它就无法离线工作。
在 pocketsphinx 中,它不会对正确的单词使用react。如果我说“下一个”,它会在另一个人的语音内容附近附加“键”,这给我带来了很多问题。是否有任何解决方案或库可以离线使用。任何离线谷歌离线语音支持。
下面是我的代码尝试了什么
package com.example.sample1;
import static edu.cmu.pocketsphinx.SpeechRecognizerSetup.defaultSetup;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import edu.cmu.pocketsphinx.RecognitionListener;
import android.app.Activity;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.TextView;
import android.widget.Toast;
import edu.cmu.pocketsphinx.Assets;
import edu.cmu.pocketsphinx.Hypothesis;
import edu.cmu.pocketsphinx.SpeechRecognizer;
public class Sam extends Activity implements RecognitionListener, TextToSpeech.OnInitListener {
/* Named searches allow to quickly reconfigure the decoder */
private static final String DIGITS_SEARCH = "digits";
private SpeechRecognizer recognizer;
private HashMap<String, Integer> captions;
private TextView caption_text;
private TextView result_text;
ArrayList<String> result1;
private Button buttonLeft;
private Button buttonRight;
int count = 0;
private ArrayList<DataAnswer> dummyListTemp;
private ArrayList<DataAnswer> dummyList;
AnswerDataAdapter listAdapter = null;
int conteo = 0;
Handler a = new Handler();
private TextToSpeech tts;
String readIt ="";
HashMap<String, String> params = new HashMap<String, String>();
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
Log.v("onCreate", "onCreate");
// Prepare the data for UI
captions = new HashMap<String, Integer>();
captions.put(DIGITS_SEARCH, R.string.digits_caption);
setContentView(R.layout.quiz);
caption_text = (TextView) findViewById(R.id.caption_text);
result_text = (TextView) findViewById(R.id.result_text);
// listViewAnswer = (ExpandableListView) findViewById(R.id.listViewAnswer);
buttonRight = (Button) findViewById(R.id.buttonRight);
buttonLeft = (Button) findViewById(R.id.buttonLeft);
result_text.setText("Result --->: ");
tts = new TextToSpeech(this, this);
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"stringId");
String text = "World is full of chanllenge";
//Speakes the text first and then after comple reading text voice recoginzation must start
speakOut(text);
buttonRight.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
//onClickRight();
Toast.makeText(getApplicationContext(), "Right", Toast.LENGTH_SHORT).show();
} catch (Exception e){
e.printStackTrace();
}
}
});
buttonLeft.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//onClickLeft();
Toast.makeText(getApplicationContext(), "Left", Toast.LENGTH_SHORT).show();
}
});
// Recognizer initialization is a time-consuming and it involves IO,
// so we execute it in async task
//if(!tts.isSpeaking()) {
new AsyncTask<Void, Void, Exception>() {
@Override
protected Exception doInBackground(Void... params) {
try {
Assets assets = new Assets(Sam.this);
File assetDir = assets.syncAssets();
Log.v("AsyncTask", "AsyncTask");
setupRecognizer(assetDir);
} catch (IOException e) {
return e;
}
return null;
}
@Override
protected void onPostExecute(Exception result) {
Log.v("onPostExecute", "onPostExecute");
try{
if (result != null) {
//caption_text.setText("Failed to init recognizer " + result);
Toast.makeText(getApplicationContext(), "Failed to init recognizer ", Toast.LENGTH_SHORT).show();
} else {
FireRecognition();
//switchSearch(DIGITS_SEARCH);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.execute();
}
@Override
public void onDestroy() {
super.onDestroy();
Log.v("onDestroy", "onDestroy");
recognizer.cancel();
recognizer.shutdown();
if (tts != null) {
tts.stop();
tts.shutdown();
}
}
public void FireRecognition(){
Log.d("Recognition","Recognition Started");
//caption_text.setText("Recognition Started!");
//Toast.makeText(getApplicationContext(), "Recognition Started!", Toast.LENGTH_SHORT).show();
recognizer.stop();
//recognizer.startListening("digits");
}
/**
* In partial result we get quick updates about current hypothesis. In
* keyword spotting mode we can react here, in other modes we need to wait
* for final result in onResult.
*/
@Override
public void onPartialResult(Hypothesis hypothesis) {
try {
//Log.v("onPartialResult", "onPartialResult");
if (hypothesis == null)
return;
Log.v("onPartialResult", hypothesis.getHypstr().toString());
String text = hypothesis.getHypstr();
if(recognizer !=null)
recognizer.stop();
caption_text.setText("Partial result -->: " + text);
Log.v("onPartialResult-->", text);
// Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* This callback is called when we stop the recognizer.
*/
@Override
public void onResult(Hypothesis hypothesis) {
try{
Log.v("onResult", "onResult");
// result_text.setText("");
if (hypothesis != null) {
String text = hypothesis.getHypstr();
//Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
// ((TextView) findViewById(R.id.result_text)).setText(text);
if(text.toLowerCase().equals("next")) {
result_text.setText("Result --->: " + text);
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
} else if(text.toLowerCase().equals("previous")) {
result_text.setText("Result --->: " + text);
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
} else if(text.toLowerCase().trim().equals("option one".toLowerCase().trim())) {
result_text.setText("Result --->: " + text);
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
result_text.setText("Result --->: " + text);
} else if(text.toLowerCase().trim().equals("option two".toLowerCase().toString())) {
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
} else if(text.toLowerCase().trim().equals("option three".toLowerCase().toString())) {
result_text.setText("Result --->: " + text);
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
} else if(text.toLowerCase().trim().equals("option four".toLowerCase().toString())) {
result_text.setText("Result --->: " + text);
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), " No Access:--" + text, Toast.LENGTH_SHORT).show();
}
Log.v("onResult-->", text);
if(recognizer != null)
recognizer.startListening("digits");
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onBeginningOfSpeech() {
Log.v("onBeginningOfSpeech", "onBeginningOfSpeech");
}
/**
* We stop recognizer here to get a final result
*/
@Override
public void onEndOfSpeech() {
Log.v("onEndOfSpeech", "onEndOfSpeech");
if (!recognizer.getSearchName().equals(DIGITS_SEARCH))
switchSearch(DIGITS_SEARCH);
}
private void switchSearch(String searchName) {
Log.v("switchSearch", "switchSearch--->" + searchName);
recognizer.stop();
// If we are not spotting, start listening with timeout (10000 ms or 10 seconds).
if (searchName.equals(DIGITS_SEARCH))
recognizer.startListening(searchName, 10000);
/* else
recognizer.startListening(searchName, 10000);*/
/* String caption = getResources().getString(captions.get(searchName));
caption_text.setText(caption);*/
}
private void setupRecognizer(File assetsDir) throws IOException {
// The recognizer can be configured to perform multiple searches
// of different kind and switch between them
Log.v("setupRecognizer", "setupRecognizer");
recognizer = defaultSetup()
.setAcousticModel(new File(assetsDir, "en-us-ptm"))
.setDictionary(new File(assetsDir, "cmudict-en-us.dict"))
// To disable logging of raw audio comment out this call (takes a lot of space on the device)
.setRawLogDir(assetsDir)
// Threshold to tune for keyphrase to balance between false alarms and misses
.setKeywordThreshold(1e-20f) //1e-20f 1e-45f
// Use context-independent phonetic search, context-dependent is too slow for mobile
// .setBoolean("-allphone_ci", true)
.getRecognizer();
recognizer.addListener(this);
/** In your application you might not need to add all those searches.
* They are added here for demonstration. You can leave just one.
*/
// Create keyword-activation search.
// recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);
// Create grammar-based search for digit recognition
File digitsGrammar = new File(assetsDir, "digits.gram");
recognizer.addGrammarSearch(DIGITS_SEARCH, digitsGrammar);
}
@Override
public void onError(Exception error) {
Log.v("onError", "onError");
//caption_text.setText(error.getMessage());
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
}
@Override
public void onTimeout() {
Log.v("onTimeout", "onTimeout");
switchSearch(DIGITS_SEARCH);
}
@SuppressWarnings("deprecation")
@Override
public void onInit(int status) {
tts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() {
@Override
public void onUtteranceCompleted(String utteranceId) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if(recognizer != null)
recognizer.startListening("digits");
//Toast.makeText(getApplicationContext(), "Completed", Toast.LENGTH_LONG).show();
}
});
}
});
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.US);
Log.i("Success", "Completed");
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
//buttonSpeak.setEnabled(true);
// speakOut();
String text = " No Voice Found".toString();
Log.i("else", "else");
// speakOut(text);
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
@SuppressWarnings("deprecation")
private void speakOut(String text) {
if(tts.isSpeaking()) {
//recognizer.stop();
}
// String text = ((TextView) findViewById(R.id.caption_text)).getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, params);
Log.i("Speaking-->", "****" + tts.isSpeaking());
}
}
而在digit.gram
#JSGF V1.0;
grammar digits;
<digit> = option one |
option two |
option three |
option four |
back |
previous |
next;
public <digits> = <digit>+;
以上是我的代码,如果有人处理过请告诉我解决方案 这是我的 xml quiz.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/linearLayout1"
android:orientation="vertical" >
<ExpandableListView
android:id="@+id/listViewAnswer"
android:layout_width="match_parent"
android:layout_height="301dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:childDivider="#334455" >
</ExpandableListView>
</LinearLayout>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/linearLayout2"
android:layout_marginTop="10dip"
android:orientation="horizontal" >
<Button
android:id="@+id/buttonRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dip"
android:text="Next" />
<Button
android:id="@+id/buttonLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:text="Previous" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/relativeLayout1" >
<TextView
android:id="@+id/result_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#556677" />
<TextView
android:id="@+id/caption_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/result_text"
android:layout_alignParentLeft="true"
android:textColor="#443399" />
</RelativeLayout>
</RelativeLayout>
更新:
如果您正在使用addKeywordSearch
File digitsGrammar = new File(context.getFilesDir(), "digits.gram");
recognizer.addKeywordSearch(DIGITS_SEARCH, digitsGrammar);
然后在digit.gram中只写
option one /1e-1/
option two /1e-1/
option three /1e-1/
option four /1e-1/
back /1e-1/
previous /1e-1/
next /1e-1/
或
如果您正在使用addGrammarSearch
File digitsGrammar = new File(context.getFilesDir(), "digits.gram");
recognizer.addGrammarSearch(DIGITS_SEARCH, digitsGrammar);
然后在digit.gram中
#JSGF V1.0;
grammar digits;
<digit> = option one |
option two |
option three |
option four |
back |
previous |
next;
public <digits> = <digit>+;
最佳答案
你需要使用关键字识别模式而不是语法模式来连续收听
你可以在这里找到例子:
关于android - 离线语音识别 android 获取不需要的语音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30916938/
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
我打算为ruby脚本创建一个安装程序,但我希望能够确保机器安装了RVM。有没有一种方法可以完全离线安装RVM并且不引人注目(通过不引人注目,就像创建一个可以做所有事情的脚本而不是要求用户向他们的bash_profile或bashrc添加一些东西)我不是要脚本本身,只是一个关于如何走这条路的快速指针(如果可能的话)。我们还研究了这个很有帮助的问题:RVM-isthereawayforsimpleofflineinstall?但有点误导,因为答案只向我们展示了如何离线在RVM中安装ruby。我们需要能够离线安装RVM本身,并查看脚本https://raw.github.com/wayn
我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只
我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121
有没有办法在这个简单的get方法中添加超时选项?我正在使用法拉第3.3。Faraday.get(url)四处寻找,我只能先发起连接后应用超时选项,然后应用超时选项。或者有什么简单的方法?这就是我现在正在做的:conn=Faraday.newresponse=conn.getdo|req|req.urlurlreq.options.timeout=2#2secondsend 最佳答案 试试这个:conn=Faraday.newdo|conn|conn.options.timeout=20endresponse=conn.get(url
我有一个存储主机名的Ruby数组server_names。如果我打印出来,它看起来像这样:["hostname.abc.com","hostname2.abc.com","hostname3.abc.com"]相当标准。我想要做的是获取这些服务器的IP(可能将它们存储在另一个变量中)。看起来IPSocket类可以做到这一点,但我不确定如何使用IPSocket类遍历它。如果它只是尝试像这样打印出IP:server_names.eachdo|name|IPSocket::getaddress(name)pnameend它提示我没有提供服务器名称。这是语法问题还是我没有正确使用类?输出:ge
我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c
我安装了ruby版本管理器,并将RVM安装的ruby实现设置为默认值,这样'哪个ruby'显示'~/.rvm/ruby-1.8.6-p383/bin/ruby'但是当我在emacs中打开inf-ruby缓冲区时,它使用安装在/usr/bin中的ruby。有没有办法让emacs像shell一样尊重ruby的路径?谢谢! 最佳答案 我创建了一个emacs扩展来将rvm集成到emacs中。如果您有兴趣,可以在这里获取:http://github.com/senny/rvm.el
假设我有这个范围:("aaaaa".."zzzzz")如何在不事先/每次生成整个项目的情况下从范围中获取第N个项目? 最佳答案 一种快速简便的方法:("aaaaa".."zzzzz").first(42).last#==>"aaabp"如果出于某种原因你不得不一遍又一遍地这样做,或者如果你需要避免为前N个元素构建中间数组,你可以这样写:moduleEnumerabledefskip(n)returnto_enum:skip,nunlessblock_given?each_with_indexdo|item,index|yieldit
我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur