質問編集履歴
1
質問を具体化
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Android
|
1
|
+
Android.speechパッケージの関係
|
body
CHANGED
@@ -1,8 +1,24 @@
|
|
1
|
-
# やりたいこと
|
2
|
-
音声データを保存しながら、音声認識しようと思い、RecognitionServiceを使いました。
|
3
|
-
|
4
|
-
`RecognitionService`
|
1
|
+
# やりたいこと bufferReceivedを使いたい
|
2
|
+
わかりずらい質問かもしれませんがよろしくお願いします。音声データを保存しながら、音声認識しようと思い、Android.speechパッケージのRecognitionServiceを使いました。調べてみたところ、`RecognitionListener`クラスの[onBufferReceived](https://developer.android.com/reference/android/speech/RecognitionListener.html#onBufferReceived(byte[]))か`RecognitionService.Callback`クラスの[bufferReceived](https://developer.android.com/reference/android/speech/RecognitionService.Callback.html#bufferReceived(byte[]))を発見しました。早速、テストで動かしてみようとしたのですが`onBufferReceived`の方は機種依存で動かないことがあるそうです。自分のAndroid端末でも動きませんでした。その次に`bufferReceived`を試そうとしました。しかし、このメソッドの使い方が分かりません。リファレンスを読んでも分かりませんでした。自分が読んで理解したのが
|
3
|
+
- `RecognitionListener`はインターフェースで、`RecognitionService.Callback`はクラス
|
4
|
+
- `RecognitionService.Callback`は`RecognitionService`と何らかの関係がある。
|
5
|
+
- 何らかの関係として`onStartListening(Intent, Callback)`の`Callback`に`bufferReceived`を使うのだろうか。
|
5
6
|
|
7
|
+
# 疑問
|
8
|
+
### その1
|
9
|
+
[RecognitionService.Callback](https://developer.android.com/reference/android/speech/RecognitionService.Callback.html)
|
10
|
+
> This class receives callbacks from the speech recognition service and forwards them to the user.
|
11
|
+
|
12
|
+
[RecognitionService](https://developer.android.com/reference/android/speech/RecognitionService.html)
|
13
|
+
> This class provides a base class for recognition service implementations.
|
14
|
+
|
15
|
+
|
16
|
+
この2つのクラスの関係を教えてください。自分で考えた感じでは、`RecognitionService`を自作クラスに継承して、`SpeechRecognizer`,`RecognitionService.Callback`はimportし、`bufferReceived`を使う。あってますか?
|
17
|
+
|
18
|
+
### その2
|
19
|
+
`bufferReceived`はどのように使うのでしょうか?返り値の型がvoidということは、音声データをマイクからストリーミング(AudioRecordクラスで行う)して取得したmybufferを`bufferReceived(mybuffer)`のように使うと、mybufferを音声認識してくれるということでしょうか?そうでないなら、このメソッドはいったい何に使うのでしょうか?
|
20
|
+
|
21
|
+
|
6
22
|
```
|
7
23
|
public class RecognitionServiceTest extends RecognitionService {
|
8
24
|
public RecognitionServiceTest(){
|