質問編集履歴
3
タイトルの修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
androidでbluetoothヘッドセットで音声認識&
|
1
|
+
androidでbluetoothヘッドセットで音声認識&読み上げがしたい
|
body
CHANGED
File without changes
|
2
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
androidで音声認識をするために以下のようなプログラムを書いたのですが、音声認識
|
1
|
+
androidで音声認識をするために以下のようなプログラムを書いたのですが、音声認識が始まった後の文章も途中からしか認識しなかったり、文章の読み上げが途中から聞こえたりします。そのタイミングもまちまちです。
|
2
2
|
そもそもこんな方法で良いのかも含め教えていただけたら幸いです。
|
3
|
+
Bluetoothを使わない状態での音声認識、読み上げは上手くいきます。
|
3
4
|
|
4
5
|
動作は、
|
5
6
|
Bluetoothヘッドセットのボタンを押す
|
1
動作の部分を詳細に
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
androidで音声認識をするために以下のようなプログラムを書いたのですが、音声認識のタイミングが遅かったり、文章の読み上げが途中から聞こえます。
|
2
2
|
そもそもこんな方法で良いのかも含め教えていただけたら幸いです。
|
3
3
|
|
4
|
+
動作は、
|
4
|
-
|
5
|
+
Bluetoothヘッドセットのボタンを押す
|
6
|
+
→ BroadcastReceiverで受け取りbluetoothHeadset.startVoiceRecognitionを行う
|
7
|
+
→ mHeadsetBroadcastReceiverでbluetoothがAUDIO_CONNECTEDを受け取り
|
8
|
+
音声認識を開始
|
9
|
+
→ 音声認識が成功したらTextToSpeechを実行
|
10
|
+
→ bluetoothHeadset.stopVoiceRecognitionでヘッドセットとの接続を終了
|
5
11
|
|
6
12
|
```Java
|
7
13
|
private SpeechRecognizer sr;
|
@@ -101,30 +107,7 @@
|
|
101
107
|
}
|
102
108
|
};
|
103
109
|
|
104
|
-
|
110
|
+
// メディアボタンが押された時
|
105
|
-
@Override
|
106
|
-
public void onInit(int status) {
|
107
|
-
if (TextToSpeech.SUCCESS == status) {
|
108
|
-
Locale locale = Locale.JAPANESE;
|
109
|
-
if (tts.isLanguageAvailable(locale) >= TextToSpeech.LANG_AVAILABLE) {
|
110
|
-
tts.setLanguage(locale);
|
111
|
-
} else {
|
112
|
-
}
|
113
|
-
} else {
|
114
|
-
}
|
115
|
-
}
|
116
|
-
|
117
|
-
private void speechText() {
|
118
|
-
if (0 < string.length()) {
|
119
|
-
if (tts.isSpeaking()) {
|
120
|
-
tts.stop();// 読み上げ中なら止める
|
121
|
-
}
|
122
|
-
Bundle bundle = new Bundle();
|
123
|
-
bundle.putString(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL));
|
124
|
-
tts.speak(ttsString, TextToSpeech.QUEUE_FLUSH, bundle, utteranceId);
|
125
|
-
}
|
126
|
-
}
|
127
|
-
|
128
111
|
public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
129
112
|
@Override
|
130
113
|
public void onReceive(Context context, Intent intent) {
|
@@ -151,6 +134,31 @@
|
|
151
134
|
}
|
152
135
|
}
|
153
136
|
|
137
|
+
|
138
|
+
// TextToSpeech
|
139
|
+
@Override
|
140
|
+
public void onInit(int status) {
|
141
|
+
if (TextToSpeech.SUCCESS == status) {
|
142
|
+
Locale locale = Locale.JAPANESE;
|
143
|
+
if (tts.isLanguageAvailable(locale) >= TextToSpeech.LANG_AVAILABLE) {
|
144
|
+
tts.setLanguage(locale);
|
145
|
+
} else {
|
146
|
+
}
|
147
|
+
} else {
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
private void speechText() {
|
152
|
+
if (0 < string.length()) {
|
153
|
+
if (tts.isSpeaking()) {
|
154
|
+
tts.stop();// 読み上げ中なら止める
|
155
|
+
}
|
156
|
+
Bundle bundle = new Bundle();
|
157
|
+
bundle.putString(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL));
|
158
|
+
tts.speak(ttsString, TextToSpeech.QUEUE_FLUSH, bundle, utteranceId);
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
154
162
|
// 音声認識を終了する
|
155
163
|
protected void stopListening() {
|
156
164
|
if (sr != null) sr.destroy();
|