大学の授業で、JavaによるAndroidアプリを開発しています。WindowsでAndroidstudioを使用しております。
私が開発しているのはビデオ通話アプリと音声文字変換アプリを組み合わせたもので、なんとか二つのコードを組み合わせているのですが、どうしてもわからない問題が二つございます。
一つ目はpublic void startRecording~@の下からの@Overrrideが全て赤字になってしまい、「メソッドはスーパークラスのメソッドをオーバーライドしてません」と出てしまいます。
二つ目は、 extends Avtivityの部分を extends AppcomoatActivityに変えたいのですが、変えると「問題が発生したためアプリを終了します」というような表示が出て起動が出来ないです。
私が組み合わせようとしているのはこの二つのコードなのでURLを貼っておきます。
https://github.com/skyway/skyway-android-sdk/blob/master/examples/p2p-videochat/app/src/main/java/com/ntt/ecl/webrtc/sample_p2p_videochat/MainActivity.java
https://github.com/servernote/AndroidSample/blob/master/VoiceToText/app/src/main/java/net/servernote/voicetotext/MainActivity.java
MainActivity
1package com.ntt.ecl.webrtc.sample_p2p_videochat; 2import androidx.appcompat.app.AppCompatActivity; 3import android.Manifest; 4//省略 5import io.skyway.Peer.PeerOption; 6 7public class MainActivity extends Activity { 8 9 private static final int PERMISSION_RECORD_AUDIO = 1; 10 11 private Button mButton; 12 private TextView mText; 13 private SpeechRecognizer mRecorder; 14 private AlertDialog.Builder mAlert; 15 16 private static final String TAG = MainActivity.class.getSimpleName(); 17 18 19 private static final String API_KEY = "\\\\\\"; 20 private static final String DOMAIN = "\\\\\\"; 21 22 private Peer _peer; 23 private MediaStream _localStream; 24 private MediaStream _remoteStream; 25 private MediaConnection _mediaConnection; 26 27 private String _strOwnId; 28 private boolean _bConnected; 29 30 private Handler _handler; 31 32 @Override 33 protected void onCreate(Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 36 setContentView(R.layout.activity_main); 37 38 _handler = new Handler(Looper.getMainLooper()); 39 final Activity activity = this; 40 41 42 PeerOption option = new PeerOption(); 43 option.key = API_KEY; 44 option.domain = DOMAIN; 45 _peer = new Peer(this, option); 46 47 48 // OPEN 49 _peer.on(Peer.PeerEventEnum.OPEN, new OnCallback() { 50 @Override 51 public void onCallback(Object object) { 52 53 //省略(URL上のサイトと同じコードです) 54 55 Button btnAction = (Button) findViewById(R.id.btnAction); 56 btnAction.setEnabled(true); 57 btnAction.setOnClickListener(new View.OnClickListener() { 58 @Override 59 public void onClick(View v) { 60 v.setEnabled(false); 61 62 if (!_bConnected) { 63 64 // Select remote peer & make a call 65 showPeerIDs(); 66 } else { 67 68 // Hang up a call 69 closeRemoteStream(); 70 _mediaConnection.close(true); 71 72 } 73 74 v.setEnabled(true); 75 } 76 }); 77 78 Button switchCameraAction = (Button) findViewById(R.id.switchCameraAction); 79 switchCameraAction.setOnClickListener(new View.OnClickListener() { 80 @Override 81 public void onClick(View v) { 82 if (null != _localStream) { 83 Boolean result = _localStream.switchCamera(); 84 if (true == result) { 85 //Success 86 } else { 87 //Failed 88 } 89 } 90 91 } 92 }); 93 94 mButton = (Button) findViewById(R.id.speech_button); 95 mText = (TextView) findViewById(R.id.output_text); 96 97 98 mRecorder = null; 99 100 mAlert = new AlertDialog.Builder(this); 101 mAlert.setTitle("エラー"); 102 mAlert.setPositiveButton("OK", null); 103 104 checkRecordable(); 105 } 106 107 public Boolean checkRecordable() { 108 if (!SpeechRecognizer.isRecognitionAvailable(getApplicationContext())) { 109 110 mText.setText("音声認識が使用できません"); 111 return false; 112 } 113 if (Build.VERSION.SDK_INT >= 23) { 114 if (ActivityCompat.checkSelfPermission(this, 115 Manifest.permission.RECORD_AUDIO) 116 != PackageManager.PERMISSION_GRANTED) { 117 mText.setText("マイクの使用を許可してください"); 118 ActivityCompat.requestPermissions(this, 119 new String[]{ 120 Manifest.permission.RECORD_AUDIO}, 121 PERMISSION_RECORD_AUDIO); 122 return false; 123 } 124 } 125 return true; 126 } 127 128 @Override 129 public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { 130 switch (requestCode) { 131 case 0: { 132 if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 133 startLocalStream(); 134 } else { 135 Toast.makeText(this, "Failed to access the camera and microphone.\nclick allow when asked for permission.", Toast.LENGTH_LONG).show(); 136 } 137 break; 138 } 139 } 140 Log.d("MainActivity", "onRequestPermissionsResult"); 141 142 if (grantResults.length <= 0) { 143 return; 144 } 145 switch (requestCode) { 146 case PERMISSION_RECORD_AUDIO: 147 if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { 148 mText.setText(""); 149 } else { 150 151 } 152 break; 153 } 154 } 155 ≀ 156 //省略(URL上のサイトと同じコードです) 157 158 void updateActionButtonTitle() { 159 _handler.post(new Runnable() { 160 @Override 161 public void run() { 162 Button btnAction = (Button) findViewById(R.id.btnAction); 163 if (null != btnAction) { 164 if (false == _bConnected) { 165 btnAction.setText("Make Call"); 166 } else { 167 btnAction.setText("Hang up"); 168 } 169 } 170 } 171 }); 172 } 173 174 public void stopRecording() { 175 if (mRecorder != null && checkRecordable()) { 176 mRecorder.stopListening(); 177 mRecorder.cancel(); 178 mRecorder.destroy(); 179 mRecorder = null; 180 mButton.setText(getString(R.string.start_speech)); 181 } 182 } 183 184 public void startRecording() { 185 if (mRecorder == null && checkRecordable()) { 186 mText.setText(getString(R.string.prepare_speech)); 187 mRecorder = SpeechRecognizer.createSpeechRecognizer(this); 188 mRecorder.setRecognitionListener((RecognitionListener) this); 189 Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 190 intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, 191 RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 192 intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, 193 getPackageName()); 194 intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); 195 mRecorder.startListening(intent); 196 mButton.setText(getString(R.string.stop_speech)); 197 } 198 } 199 200 @Override 201 public void onClick(View v) { 202 if(v.getId() != R.id.speech_button){ 203 return; 204 } 205 if(mRecorder != null){ 206 stopRecording(); 207 } 208 else{ 209 startRecording(); 210 } 211 } 212 213 @Override 214 public void onReadyForSpeech(Bundle params) { 215 Log.d("MainActivity","onReadyForSpeech"); 216 mText.setText(getString(R.string.ready_speech)); 217 } 218 219 @Override 220 public void onBeginningOfSpeech() { 221 Log.d("MainActivity","onBeginningOfSpeech"); 222 mText.setText(""); 223 } 224 225 @Override 226 public void onBufferReceived(byte[] buffer) { 227 Log.d("MainActivity","onBufferReceived"); 228 } 229 230 @Override 231 public void onRmsChanged(float rmsdB) { 232 Log.d("MainActivity","onRmsChanged"); 233 } 234 235 @Override 236 public void onEndOfSpeech() { 237 Log.d("MainActivity","onEndOfSpeech"); 238 stopRecording(); 239 } 240 241 @Override 242 public void onError(int error) { 243 Log.d("MainActivity","onError.error="+error); 244 mText.setText(getString(R.string.speech_error) + "\nエラーコード:" + error); 245 stopRecording(); 246 } 247 248 @Override 249 public void onEvent(int eventType, Bundle params) { 250 Log.d("MainActivity","onEvent.eventType="+eventType); 251 } 252 253 @Override 254 public void onPartialResults(Bundle partialResults) { 255 Log.d("MainActivity","onPartialResults"); 256 String str = partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION).get(0); 257 if(str.length() > 0) { 258 mText.setText(str); 259 } 260 } 261 262 @Override 263 public void onResults(Bundle results) { 264 Log.d("MainActivity","onResults"); 265 } 266}
回答していただけるとありがたいです。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー