Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add bitrate to ios and audio channels to android #540

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class RNAudioRecorderPlayerModule(private val reactContext: ReactApplicationCont
mediaRecorder!!.setAudioEncoder(if (audioSet.hasKey("AudioEncoderAndroid")) audioSet.getInt("AudioEncoderAndroid") else MediaRecorder.AudioEncoder.AAC)
mediaRecorder!!.setAudioSamplingRate(if (audioSet.hasKey("AudioSamplingRateAndroid")) audioSet.getInt("AudioSamplingRateAndroid") else 48000)
mediaRecorder!!.setAudioEncodingBitRate(if (audioSet.hasKey("AudioEncodingBitRateAndroid")) audioSet.getInt("AudioEncodingBitRateAndroid") else 128000)
mediaRecorder!!.setAudioChannels(if (audioSet.hasKey("AudioChannelsAndroid")) audioSet.getInt("AudioChannelsAndroid") else 2)
} else {
mediaRecorder!!.setAudioSource(MediaRecorder.AudioSource.MIC)
mediaRecorder!!.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
Expand Down
2 changes: 2 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ export interface AudioSet {
AVLinearPCMIsBigEndianKeyIOS?: boolean;
AVLinearPCMIsFloatKeyIOS?: boolean;
AVLinearPCMIsNonInterleavedIOS?: boolean;
AVEncoderBitRateKeyIOS?: number;
OutputFormatAndroid?: OutputFormatAndroidType;
AudioEncoderAndroid?: AudioEncoderAndroidType;
AudioEncodingBitRateAndroid?: number;
AudioSamplingRateAndroid?: number;
AudioChannelsAndroid?: number;
}

const pad = (num: number): string => {
Expand Down
8 changes: 7 additions & 1 deletion ios/RNAudioRecorderPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class RNAudioRecorderPlayer: RCTEventEmitter, AVAudioRecorderDelegate {
var sampleRate = audioSets["AVSampleRateKeyIOS"] as? Int
var numberOfChannel = audioSets["AVNumberOfChannelsKeyIOS"] as? Int
var audioQuality = audioSets["AVEncoderAudioQualityKeyIOS"] as? Int
var bitRate = audioSets["AVEncoderBitRateKeyIOS"] as? Int

setAudioFileURL(path: path)

Expand Down Expand Up @@ -232,6 +233,10 @@ class RNAudioRecorderPlayer: RCTEventEmitter, AVAudioRecorderDelegate {
audioQuality = AVAudioQuality.medium.rawValue
}

if (bitRate == nil) {
bitRate = 128000
}

func startRecording() {
let settings = [
AVSampleRateKey: sampleRate!,
Expand All @@ -241,7 +246,8 @@ class RNAudioRecorderPlayer: RCTEventEmitter, AVAudioRecorderDelegate {
AVLinearPCMBitDepthKey: avLPCMBitDepth ?? AVLinearPCMBitDepthKey.count,
AVLinearPCMIsBigEndianKey: avLPCMIsBigEndian ?? true,
AVLinearPCMIsFloatKey: avLPCMIsFloatKey ?? false,
AVLinearPCMIsNonInterleaved: avLPCMIsNonInterleaved ?? false
AVLinearPCMIsNonInterleaved: avLPCMIsNonInterleaved ?? false,
AVEncoderBitRateKey: bitRate!
] as [String : Any]

do {
Expand Down