質問編集履歴
3
タイトルの修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
androidでbluetoothヘッドセットで音声認識&
|
1
|
+
androidでbluetoothヘッドセットで音声認識&読み上げがしたい
|
test
CHANGED
File without changes
|
2
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
androidで音声認識をするために以下のようなプログラムを書いたのですが、音声認識の
|
1
|
+
androidで音声認識をするために以下のようなプログラムを書いたのですが、音声認識が始まった後の文章も途中からしか認識しなかったり、文章の読み上げが途中から聞こえたりします。そのタイミングもまちまちです。
|
2
2
|
|
3
3
|
そもそもこんな方法で良いのかも含め教えていただけたら幸いです。
|
4
4
|
|
5
|
+
Bluetoothを使わない状態での音声認識、読み上げは上手くいきます。
|
6
|
+
|
5
7
|
|
6
8
|
|
7
9
|
動作は、
|
1
動作の部分を詳細に
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,19 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
+
動作は、
|
8
|
+
|
7
|
-
|
9
|
+
Bluetoothヘッドセットのボタンを押す
|
10
|
+
|
11
|
+
→ BroadcastReceiverで受け取りbluetoothHeadset.startVoiceRecognitionを行う
|
12
|
+
|
13
|
+
→ mHeadsetBroadcastReceiverでbluetoothがAUDIO_CONNECTEDを受け取り
|
14
|
+
|
15
|
+
音声認識を開始
|
16
|
+
|
17
|
+
→ 音声認識が成功したらTextToSpeechを実行
|
18
|
+
|
19
|
+
→ bluetoothHeadset.stopVoiceRecognitionでヘッドセットとの接続を終了
|
8
20
|
|
9
21
|
|
10
22
|
|
@@ -204,6 +216,62 @@
|
|
204
216
|
|
205
217
|
|
206
218
|
|
219
|
+
// メディアボタンが押された時
|
220
|
+
|
221
|
+
public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
222
|
+
|
223
|
+
@Override
|
224
|
+
|
225
|
+
public void onReceive(Context context, Intent intent) {
|
226
|
+
|
227
|
+
String intentAction = intent.getAction();
|
228
|
+
|
229
|
+
if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
|
230
|
+
|
231
|
+
return;
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
|
236
|
+
|
237
|
+
if (event == null) {
|
238
|
+
|
239
|
+
return;
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
int action = event.getAction();
|
244
|
+
|
245
|
+
if (action == KeyEvent.ACTION_DOWN) {
|
246
|
+
|
247
|
+
if (sr == null) {
|
248
|
+
|
249
|
+
sr = SpeechRecognizer.createSpeechRecognizer(this);
|
250
|
+
|
251
|
+
sr.setRecognitionListener(new listener());
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
if (tts.isSpeaking()) {
|
256
|
+
|
257
|
+
tts.stop(); // 読み上げ中なら止める
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
mBluetoothHeadset.startVoiceRecognition(bluetoothDevice);
|
264
|
+
|
265
|
+
abortBroadcast();
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
|
274
|
+
|
207
275
|
// TextToSpeech
|
208
276
|
|
209
277
|
@Override
|
@@ -252,58 +320,6 @@
|
|
252
320
|
|
253
321
|
|
254
322
|
|
255
|
-
public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
256
|
-
|
257
|
-
@Override
|
258
|
-
|
259
|
-
public void onReceive(Context context, Intent intent) {
|
260
|
-
|
261
|
-
String intentAction = intent.getAction();
|
262
|
-
|
263
|
-
if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
|
264
|
-
|
265
|
-
return;
|
266
|
-
|
267
|
-
}
|
268
|
-
|
269
|
-
KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
|
270
|
-
|
271
|
-
if (event == null) {
|
272
|
-
|
273
|
-
return;
|
274
|
-
|
275
|
-
}
|
276
|
-
|
277
|
-
int action = event.getAction();
|
278
|
-
|
279
|
-
if (action == KeyEvent.ACTION_DOWN) {
|
280
|
-
|
281
|
-
if (sr == null) {
|
282
|
-
|
283
|
-
sr = SpeechRecognizer.createSpeechRecognizer(this);
|
284
|
-
|
285
|
-
sr.setRecognitionListener(new listener());
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
if (tts.isSpeaking()) {
|
290
|
-
|
291
|
-
tts.stop(); // 読み上げ中なら止める
|
292
|
-
|
293
|
-
}
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
mBluetoothHeadset.startVoiceRecognition(bluetoothDevice);
|
298
|
-
|
299
|
-
abortBroadcast();
|
300
|
-
|
301
|
-
}
|
302
|
-
|
303
|
-
}
|
304
|
-
|
305
|
-
|
306
|
-
|
307
323
|
// 音声認識を終了する
|
308
324
|
|
309
325
|
protected void stopListening() {
|