當前位置:首頁 » 安卓系統 » android語音demo

android語音demo

發布時間: 2025-01-17 14:19:25

⑴ 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雲端反饋的數據即可。

⑵ 如何用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/e.cmu.pocketsphinx/hmm/en_US/hub4wsj_sc_8k
/sdcard/Android/data/e.cmu.pocketsphinx/lm/en_US/hub4.5000.dic
/sdcard/Android/data/e.cmu.pocketsphinx/lm/en_US/hub4.5000.DMP

7.在PocketSphinxDemo項目中使 RecognizerTask.java里c.setString函數中的參數符合6中存放的文件和文件夾。
8.構建運行

⑶ android 怎麼實現語音聊天

可以用第三方即時通訊雲服務商,也可以自己開發實現。看你公司的能力和需求。自己開發耗時耗人耗精力。用第三方,比如融雲,這里就舉個融雲的例子吧。 可以直接集成融雲的sdk,然後直接實現你說的功能。優點是快速方便,服務穩定。缺點是:不是自己開發的,如果出現問題需要提工單解決。

⑷ 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 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怎樣實現中文語音朗讀

官方現在支持中文,下載eSpeak這個語音包,google code就能搜索到。eSpeak支持60種語言,包括中文。不過中文很難聽就是。
國內也有一些語音包支持中文朗讀,比如手說tts。

⑹ android 怎麼自動打開文字轉語音設置界面

,多謝這位兄台,問題解決了。已找到可以跳轉的方法,我實在4.4.2系統上測試的,可行,代碼現貼出來,供參考:Intent
intent
=
new
Intent();intent.setAction("com.android.settings.TTS_SETTINGS");intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(intent);

熱點內容
火影忍者競技場腳本 發布:2025-02-08 23:10:18 瀏覽:934
英國訪問學者簽證費用 發布:2025-02-08 23:04:46 瀏覽:926
洛奇合成腳本 發布:2025-02-08 22:57:04 瀏覽:141
linux文件軟鏈接 發布:2025-02-08 22:35:48 瀏覽:773
iphone6s緩存怎麼清理 發布:2025-02-08 22:33:17 瀏覽:928
資料庫系統設計的步驟 發布:2025-02-08 22:11:19 瀏覽:44
processc語言 發布:2025-02-08 22:11:15 瀏覽:537
國產車配置為什麼這么便宜 發布:2025-02-08 22:09:52 瀏覽:481
伺服器為什麼需要專線 發布:2025-02-08 22:07:27 瀏覽:872
java正則表達式正則替換 發布:2025-02-08 22:01:04 瀏覽:506