录音时如何获取 当前输入的音量大小
audioManager.registerAudioCapturerCallback(callback);
AudioDeviceDescriptor[] devices = AudioManager.getDevices(AudioDeviceDescriptor.DeviceFlag.INPUT_DEVICES_FLAG);
AudioDeviceDescriptor currentAudioType = devices[0];
AudioCapturerInfo.AudioInputSource source = AudioCapturerInfo.AudioInputSource.AUDIO_INPUT_SOURCE_MIC;
AudioStreamInfo audioStreamInfo = new AudioStreamInfo.Builder().audioStreamFlag(
AudioStreamInfo.AudioStreamFlag.AUDIO_STREAM_FLAG_AUDIBILITY_ENFORCED)
.encodingFormat(AudioStreamInfo.EncodingFormat.ENCODING_PCM_16BIT)
.channelMask(AudioStreamInfo.ChannelMask.CHANNEL_IN_STEREO)
.streamUsage(AudioStreamInfo.StreamUsage.STREAM_USAGE_MEDIA)
.sampleRate(SAMPLE_RATE)
.build();
AudioCapturerInfo audioCapturerInfo = new AudioCapturerInfo.Builder().audioStreamInfo(audioStreamInfo)
.audioInputSource(source)
.build();
audioCapturer = new AudioCapturer(audioCapturerInfo, currentAudioType);
这里可以参考一下:
https://gitee.com/openharmony-tpc/ohosMP3Recorder/blob/master/mp3recorderlib/src/main/java/com/czt/mp3recorder/MP3Recorder.java