我已经安装了PocketSphinx演示,它在Ubuntu和Eclipse下运行良好,但是尽管尝试过,我还是不知道如何添加对多个单词的识别。
我只想让代码识别单个单词,然后我可以在代码中切换()
,例如“up”、“down”、“left”、“right”。我不想识别句子,只想识别单个单词。
在这方面的任何帮助都将不胜感激。我发现其他用户也有类似的问题,但到目前为止还没有人知道答案。
让我困惑的一件事是,为什么我们需要使用“唤醒”常数?
private static final String KWS_SEARCH = "wakeup";
private static final String KEYPHRASE = "oh mighty computer";
.
.
.
recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);
wakeup
和什么有关系?
我取得了一些进展(?):使用addGrammarSearch
我可以使用。gram
文件列出我的单词,例如向上、向下、向左、向右、向前、向后
,如果我所说的都是那些特定的单词,这似乎很有效。但是,任何其他单词都会导致系统将所说的与所述单词中“最近”的单词匹配。理想情况下,如果所说的单词不在中,我不希望出现识别。gram
文件。。。
正在更新安提诺乌斯修正案的PocketSphinx演示,以允许它在Android Studio上运行。这是我目前所拥有的,
//Note: change MainActivity to PocketSphinxActivity for demo use...
public class MainActivity extends Activity implements RecognitionListener {
private static final String DIGITS_SEARCH = "digits";
private SpeechRecognizer recognizer;
/* Used to handle permission request */
private static final int PERMISSIONS_REQUEST_RECORD_AUDIO = 1;
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.main);
((TextView) findViewById(R.id.caption_text))
.setText("Preparing the recognizer");
// Check if user has given permission to record audio
int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.RECORD_AUDIO);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, PERMISSIONS_REQUEST_RECORD_AUDIO);
return;
}
new AsyncTask<Void, Void, Exception>() {
@Override
protected Exception doInBackground(Void... params) {
try {
Assets assets = new Assets(MainActivity.this);
File assetDir = assets.syncAssets();
setupRecognizer(assetDir);
} catch (IOException e) {
return e;
}
return null;
}
@Override
protected void onPostExecute(Exception result) {
if (result != null) {
((TextView) findViewById(R.id.caption_text))
.setText("Failed to init recognizer " + result);
} else {
reset();
}
}
}.execute();
((TextView) findViewById(R.id.caption_text)).setText("Say one, two, three, four, five, six...");
}
/**
* 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) {
if (hypothesis == null) {
return;
} else if (hypothesis != null) {
if (recognizer != null) {
//recognizer.rapidSphinxPartialResult(hypothesis.getHypstr());
String text = hypothesis.getHypstr();
if (text.equals(DIGITS_SEARCH)) {
recognizer.cancel();
performAction();
recognizer.startListening(DIGITS_SEARCH);
}else{
//Toast.makeText(getApplicationContext(),"Partial result = " +text,Toast.LENGTH_SHORT).show();
}
}
}
}
@Override
public void onResult(Hypothesis hypothesis) {
((TextView) findViewById(R.id.result_text)).setText("");
if (hypothesis != null) {
String text = hypothesis.getHypstr();
makeText(getApplicationContext(), "Hypothesis" +text, Toast.LENGTH_SHORT).show();
}else if(hypothesis == null){
makeText(getApplicationContext(), "hypothesis = null", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onDestroy() {
super.onDestroy();
recognizer.cancel();
recognizer.shutdown();
}
@Override
public void onBeginningOfSpeech() {
}
@Override
public void onEndOfSpeech() {
reset();
}
@Override
public void onTimeout() {
}
private void setupRecognizer(File assetsDir) throws IOException {
// The recognizer can be configured to perform multiple searches
// of different kind and switch between them
recognizer = defaultSetup()
.setAcousticModel(new File(assetsDir, "en-us-ptm"))
.setDictionary(new File(assetsDir, "cmudict-en-us.dict"))
// .setRawLogDir(assetsDir).setKeywordThreshold(1e-20f)
.getRecognizer();
recognizer.addListener(this);
File digitsGrammar = new File(assetsDir, "digits.gram");
recognizer.addKeywordSearch(DIGITS_SEARCH, digitsGrammar);
}
private void reset(){
recognizer.stop();
recognizer.startListening(DIGITS_SEARCH);
}
@Override
public void onError(Exception error) {
((TextView) findViewById(R.id.caption_text)).setText(error.getMessage());
}
public void performAction() {
// do here whatever you want
makeText(getApplicationContext(), "performAction done... ", Toast.LENGTH_SHORT).show();
}
}
买方注意:这是半成品。稍后再检查。如能提出建议,将不胜感激。
您可以使用addKeywordSearch
,它用于使用关键字短语进行归档。例如,每行一个短语,每个短语在//中都有阈值
up /1.0/
down /1.0/
left /1.0/
right /1.0/
forwards /1e-1/
必须选择阈值以避免误报。
多亏了尼古拉的提示(见上面的答案),我开发了以下代码,运行良好,除非单词在列表中,否则无法识别它们。您可以将其直接复制并粘贴到PocketSphinxDemo代码中的主类上:
public class PocketSphinxActivity extends Activity implements RecognitionListener
{
private static final String DIGITS_SEARCH = "digits";
private SpeechRecognizer recognizer;
@Override
public void onCreate(Bundle state)
{
super.onCreate(state);
setContentView(R.layout.main);
((TextView) findViewById(R.id.caption_text)).setText("Preparing the recognizer");
try
{
Assets assets = new Assets(PocketSphinxActivity.this);
File assetDir = assets.syncAssets();
setupRecognizer(assetDir);
}
catch (IOException e)
{
// oops
}
((TextView) findViewById(R.id.caption_text)).setText("Say up, down, left, right, forwards, backwards");
reset();
}
@Override
public void onPartialResult(Hypothesis hypothesis)
{
}
@Override
public void onResult(Hypothesis hypothesis)
{
((TextView) findViewById(R.id.result_text)).setText("");
if (hypothesis != null)
{
String text = hypothesis.getHypstr();
makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
}
}
@Override
public void onBeginningOfSpeech()
{
}
@Override
public void onEndOfSpeech()
{
reset();
}
private void setupRecognizer(File assetsDir)
{
File modelsDir = new File(assetsDir, "models");
recognizer = defaultSetup().setAcousticModel(new File(modelsDir, "hmm/en-us-semi"))
.setDictionary(new File(modelsDir, "dict/cmu07a.dic"))
.setRawLogDir(assetsDir).setKeywordThreshold(1e-20f)
.getRecognizer();
recognizer.addListener(this);
File digitsGrammar = new File(modelsDir, "grammar/digits.gram");
recognizer.addKeywordSearch(DIGITS_SEARCH, digitsGrammar);
}
private void reset()
{
recognizer.stop();
recognizer.startListening(DIGITS_SEARCH);
}
}
您的数字。gram
文件应类似于:
up /1e-1/
down /1e-1/
left /1e-1/
right /1e-1/
forwards /1e-1/
backwards /1e-1/
您应该在双斜杠/
中尝试阈值以提高性能,其中1e-1
表示0.1(我认为)。我认为最大值是1.0
。
现在是下午5:30,所以我现在可以停止工作了。结果。
问题内容: 我的数据库中有三个表: 这些表中的每个表都有两个字段,分别称为“内容”和“标题”。我希望能够在我的sql语句中使用“赞”来查看“ messages.content”,“ messages.title”,“ topics.content”,“ topics.title”,“ comments.content”和“ comments”。标题”使用关键字。 到目前为止,我的查询仅能从一张表中
我正在寻找创建应用程序,以验证用户使用面部识别。 我检查了Android是否提供生物识别提示来验证用户身份,但我不确定这个API是否可以用于我的用例。另外,如果我能使用这个API,手机上可以存储多少面部数据,这些数据将存储在哪里? 如果我不能实现我正在寻找的东西,通过面部识别,这是否可以使用指纹认证来完成。如果是,一个设备上可以存储多少指纹?
这是微软公司研究人员开发的最新的适用于嵌入式设备上的语言识别系统的源代码,继承了优秀语音识别软件sphinx的优点,用于开发嵌入式系统上的应用。
我正在将应用程序从一个服务器迁移到另一个服务器。根据这个应用程序的连接字符串,它正在接触不同的数据库。这意味着DB1中的视图查询将触及DB2中的表。因此,在迁移这个应用程序时,我经常看到“数据库不可用”的错误链,每次我看到这样的错误,我必须迁移特定的数据库。 我想知道,既然我们有ER图来了解数据库中表之间的关系,那么在SQL server中是否有任何方法来了解服务器中不同数据库之间的关系/链接?有
问题内容: 我在OCJP for Java6的书中读到了带有断言的部分。我到达了那一部分,它概述了如果将“ assert”一词用作关键字或标识符时编译器的反应。 a 和an有什么区别?谁能给我一个简单的解释,并同时给我一个或多个例子? 问题答案: 术语“关键字”和“标识符”不是Java特定的。 关键字是Java关键字列表中的保留字,可为编译器提供指令。由于保留了关键字,因此程序员不能将其用于变量或
主要内容:标识符,关键字任何一种计算机语言都离不开标识符和关键字,因此下面将详细介绍 Java 的标识符、关键字和保留字。 标识符 Java 中标识符是为方法、变量或其他用户定义项所定义的名称。标识符可以有一个或多个字符。在 Java 语言中,标识符的构成规则如下。 标识符由数字(0~9)和字母(A~Z 和 a~z)、美元符号($)、下划线(_)以及 Unicode 字符集中符号大于 0xC0 的所有符号组合构成(各符号