/*
* Copyright (C) 2010 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.android.voicedialer;
import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.media.ToneGenerator;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.SystemProperties;
import android.os.Vibrator;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
/**
* TODO: get rid of the anonymous classes
*
* This class is the user interface of the VoiceDialer application.
* It begins in the INITIALIZING state.
*
* INITIALIZING :
* This transitions out on events from TTS and the BluetoothHeadset
* once TTS initialized and SCO channel set up:
* * prompt the user "speak now"
* * transition to the SPEAKING_GREETING state
*
* SPEAKING_GREETING:
* This transitions out only on events from TTS or the fallback runnable
* once the greeting utterance completes:
* * begin listening for the command using the {@link CommandRecognizerEngine}
* * transition to the WAITING_FOR_COMMAND state
*
* WAITING_FOR_COMMAND :
* This transitions out only on events from the recognizer
* on RecognitionFailure or RecognitionError:
* * begin speaking "try again."
* * transition to state SPEAKING_TRY_AGAIN
* on RecognitionSuccess:
* single result:
* * begin speaking the sentence describing the intent
* * transition to the SPEAKING_CHOSEN_ACTION
* multiple results:
* * begin speaking each of the choices in order
* * transition to the SPEAKING_CHOICES state
*
* SPEAKING_TRY_AGAIN:
* This transitions out only on events from TTS or the fallback runnable
* once the try again utterance completes:
* * begin listening for the command using the {@link CommandRecognizerEngine}
* * transition to the LISTENING_FOR_COMMAND state
*
* SPEAKING_CHOSEN_ACTION:
* This transitions out only on events from TTS or the fallback runnable
* once the utterance completes:
* * dispatch the intent that was chosen
* * transition to the EXITING state
* * finish the activity
*
* SPEAKING_CHOICES:
* This transitions out only on events from TTS or the fallback runnable
* once the utterance completes:
* * begin listening for the user's choice using the
* {@link PhoneTypeChoiceRecognizerEngine}
* * transition to the WAITING_FOR_CHOICE state.
*
* WAITING_FOR_CHOICE:
* This transitions out only on events from the recognizer
* on RecognitionFailure or RecognitionError:
* * begin speaking the "invalid choice" message, along with the list
* of choices
* * transition to the SPEAKING_CHOICES state
* on RecognitionSuccess:
* if the result is "try again", prompt the user to say a command, begin
* listening for the command, and transition back to the WAITING_FOR_COMMAND
* state.
* if the result is "exit", then being speaking the "goodbye" message and
* transition to the SPEAKING_GOODBYE state.
* if the result is a valid choice, begin speaking the action chosen,initiate
* the command the user has choose and exit.
* if not a valid choice, speak the "invalid choice" message, begin
* speaking the choices in order again, transition to the
* SPEAKING_CHOICES
*
* SPEAKING_GOODBYE:
* This transitions out only on events from TTS or the fallback runnable
* after a time out, finish the activity.
*
*/
public class VoiceDialerActivity extends Activity {
private static final String TAG = "VoiceDialerActivity";
private static final String MICROPHONE_EXTRA = "microphone";
private static final String CONTACTS_EXTRA = "contacts";
private static final String SPEAK_NOW_UTTERANCE = "speak_now";
private static final String TRY_AGAIN_UTTERANCE = "try_again";
private static final String CHOSEN_ACTION_UTTERANCE = "chose_action";
private static final String GOODBYE_UTTERANCE = "goodbye";
private static final String CHOICES_UTTERANCE = "choices";
private static final int FIRST_UTTERANCE_DELAY = 300;
private static final int MAX_TTS_DELAY = 6000;
private static final int EXIT_DELAY = 2000;
private static final int BLUETOOTH_SAMPLE_RATE = 8000;
private static final int REGULAR_SAMPLE_RATE = 11025;
private static final int INITIALIZING = 0;
private static final int SPEAKING_GREETING = 1;
private static final int WAITING_FOR_COMMAND = 2;
private static final int SPEAKING_TRY_AGAIN = 3;
private static final int SPEAKING_CHOICES = 4;
private static final int WAITING_FOR_CHOICE = 5;
private static final int WAITING_FOR_DIALOG_CHOICE = 6;
private static final int SPEAKING_CHOSEN_ACTION = 7;
private static final int SPEAKING_GOODBYE = 8;
private static final int EXITING = 9;
private static final CommandRecognizerEngine mCommandEngine =
new CommandRecognizerEngine();
private static final PhoneTypeChoiceRecognizerEngine mPhoneTypeChoiceEngine =
new PhoneTypeChoiceRecognizerEngine();
private CommandRecognizerClient mCommandClient;
private ChoiceRecognizerClient mChoiceClient;
private ToneGenerator mToneGenerator;
private Handler mHandler;
private Thread mRecognizerThread = null;
private AudioManager mAudioManager;
private BluetoothHeadset mBluetoothHeadset;
private BluetoothDevice mBluetoothDevice;
private BluetoothAdapter mAdapter;
private TextToSpeech mTts;
private HashMap<String, String> mTtsParams;
private VoiceDialerBroadcastReceiver mReceiver;
private boolean mWaitingForTts;
private boolean mWaitingForScoConnection;
private Intent[] mAvailableChoices;
private Intent mChosenAction;
private int mBluetoothVoiceVolume;
private int mState;
private AlertDialog mAlertDialog;
private Runnable mFallbackRunnable;
private boolean mUsingBluetooth = false;
private int mSampleRate;
private WakeLock mWakeLock;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
// TODO: All of this state management and holding of
// connections to the TTS engine and recognizer really
// belongs in a service. The activity can be stopped or deleted
// and recreated for lots of reasons.
// It's way too late in the ICS release cycle for a change
// like this now though.
// MHibdon Sept 20 2011
mHandler = new Handler();
mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
mToneGenerator = new ToneGenerator(AudioManager.STREAM_RING,
ToneGenerator.MAX_VOLUME);
acquireWakeLock(this);
mState = INITIALIZING;
mChosenAction = null;
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Android应用源码之VoiceDialer-IT计算机-毕业设计.zip (77个子文件)
Android应用源码之VoiceDialer
VoiceDialer
NOTICE 10KB
res
values-nb
strings.xml 3KB
values-zu
strings.xml 3KB
values-sk
strings.xml 3KB
values-ca
strings.xml 3KB
values-fr
strings.xml 3KB
values-uk
strings.xml 3KB
values-af
strings.xml 3KB
values-lt
strings.xml 3KB
values-hi
strings.xml 4KB
values-ru
strings.xml 4KB
values-hr
strings.xml 3KB
values-es
strings.xml 3KB
values-cs
strings.xml 3KB
values-th
strings.xml 4KB
values-de
strings.xml 3KB
values-ms
strings.xml 3KB
drawable-hdpi
ic_vd_green_key.png 670B
ic_vd_mic_off.png 5KB
ic_vd_mic_on.png 4KB
app_voicedialer.png 5KB
ic_vd_retry.png 3KB
values-sw
strings.xml 3KB
values-pl
strings.xml 3KB
values-fi
strings.xml 3KB
values-sl
strings.xml 3KB
values-tl
strings.xml 3KB
values-am
strings.xml 3KB
values-ro
strings.xml 3KB
values-in
strings.xml 3KB
values-sv
strings.xml 3KB
values-ja
strings.xml 3KB
values-ko
strings.xml 3KB
values-pt
strings.xml 3KB
values
strings.xml 5KB
values-ar
strings.xml 3KB
values-da
strings.xml 3KB
values-tr
strings.xml 3KB
values-zh-rTW
strings.xml 3KB
values-rm
strings.xml 3KB
values-es-rUS
strings.xml 3KB
drawable-mdpi
ic_vd_green_key.png 620B
ic_vd_mic_off.png 3KB
ic_vd_mic_on.png 2KB
app_voicedialer.png 3KB
ic_vd_retry.png 2KB
values-zh-rCN
strings.xml 3KB
values-hu
strings.xml 3KB
values-en-rGB
strings.xml 3KB
values-lv
strings.xml 3KB
values-nl
strings.xml 3KB
values-el
strings.xml 4KB
values-sr
strings.xml 4KB
values-pt-rPT
strings.xml 3KB
values-iw
strings.xml 3KB
values-bg
strings.xml 4KB
layout
tool_tip.xml 2KB
voice_dialing.xml 2KB
values-fa
strings.xml 4KB
values-vi
strings.xml 3KB
values-it
strings.xml 3KB
tests
Android.mk 357B
src
com
android
voicedialer
VoiceDialerLaunchPerformance.java 1KB
AndroidManifest.xml 1KB
Android.mk 300B
src
com
android
voicedialer
RecognizerEngine.java 9KB
RecognizerLogger.java 8KB
VoiceDialerReceiver.java 3KB
RecognizerClient.java 1KB
VoiceDialerActivity.java 47KB
VoiceContact.java 11KB
VoiceDialerTester.java 8KB
CommandRecognizerEngine.java 46KB
PhoneTypeChoiceRecognizerEngine.java 4KB
MODULE_LICENSE_APACHE2 0B
CleanSpec.mk 2KB
AndroidManifest.xml 3KB
共 77 条
- 1
资源评论
芝麻粒儿
- 粉丝: 6w+
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功