我正在尝试使用 tarsosdsp 增加麦克风音量。我尝试使用录音机,但它一直说我的应用程序正在使用麦克风,我需要关闭我的应用程序才能工作。有人可以指导我如何在允许其他应用程序使用麦克风的同时增加麦克风音量吗?这是我的以下代码:
package com.example.microphonebooster;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.SeekBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import be.tarsos.dsp.AudioDispatcher;
import be.tarsos.dsp.AudioEvent;
import be.tarsos.dsp.AudioProcessor;
import be.tarsos.dsp.GainProcessor;
import be.tarsos.dsp.io.android.AudioDispatcherFactory;
public class MainActivity extends AppCompatActivity {
private final static String TAG = "SOUND";
private AudioDispatcher dispatcher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);
requestRecordAudioPermission();
SeekBar seekBar = (SeekBar) findViewById(R.id.percentage);
AudioProcessor soundPressureProcessor = new AudioProcessor() {
@Override
public boolean process(AudioEvent audioEvent) {
runOnUiThread(new Runnable() {
@Override
public void run() {
int x = seekBar.getProgress();
GainProcessor idk = new GainProcessor(x);
Log.d("xd","reached here");
}
});
return true;
}
@Override
public void processingFinished() {
}
};
dispatcher.addAudioProcessor(soundPressureProcessor);
new Thread(dispatcher, "Dispatcher").start();
}
// see https://developer.android.com/training/permissions/requesting.html
private void requestRecordAudioPermission() {
int apiVersion = Build.VERSION.SDK_INT;
if (apiVersion > Build.VERSION_CODES.LOLLIPOP) {
ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.RECORD_AUDIO}, 1);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case 1: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Permission granted");
}
else {
Log.d(TAG, "Permission denied");
finish();
}
}
}
}
}