0

我正在尝试使用 Tarsosdsp 库来增加麦克风音量。我写了一些代码,但声音似乎根本没有改变。

公共类 MainActivity 扩展 AppCompatActivity {

private final static String TAG = "SOUND";

private AudioDispatcher dispatcher;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    requestRecordAudioPermission();
    dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);
    SeekBar seekBar = (SeekBar) findViewById(R.id.percentage);

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            int x = seekBar.getProgress();
            new GainProcessor(x);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
    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();
            }
        }
    }
}}

有人可以告诉我我做错了什么,或者是否有示例代码可以做到这一点,我将不胜感激。

4

0 回答 0