Skip to content

Commit

Permalink
chore: Rework Darwin package
Browse files Browse the repository at this point in the history
  • Loading branch information
llfbandit committed Nov 3, 2023
1 parent 128380a commit c4ea8d1
Show file tree
Hide file tree
Showing 20 changed files with 660 additions and 481 deletions.
6 changes: 4 additions & 2 deletions record/example/lib/audio_recorder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ class _RecorderState extends State<Recorder> with AudioRecorderMixin {
Future<void> _start() async {
try {
if (await _audioRecorder.hasPermission()) {
const encoder = AudioEncoder.wav;
const encoder = AudioEncoder.aacLc;

// We don't do anything with this but printing
final isSupported = await _audioRecorder.isEncoderSupported(
encoder,
);

debugPrint('${encoder.name} supported: $isSupported');
if (!isSupported) {
debugPrint('${encoder.name} supported: $isSupported');
}

final devs = await _audioRecorder.listInputDevices();
debugPrint(devs.toString());
Expand Down
9 changes: 7 additions & 2 deletions record/example/lib/platform/audio_recorder_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ mixin AudioRecorderMixin {
}

Future<void> recordStream(AudioRecorder recorder, RecordConfig config) async {
final file = File(await _getPath());
final path = await _getPath();

final file = File(path);

final stream = await recorder.startStream(config);

Expand All @@ -26,7 +28,10 @@ mixin AudioRecorderMixin {
file.writeAsBytesSync(data, mode: FileMode.append);
},
// ignore: avoid_print
onDone: () => print('End of stream'),
onDone: () {
// ignore: avoid_print
print('End of stream. File written to $path.');
},
);
}

Expand Down
2 changes: 1 addition & 1 deletion record/example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
5 changes: 5 additions & 0 deletions record_darwin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.0.1-beta.1
* chore: Reworked again implementations to be closer to previous versions:
- iOS Simulator is now usable again.
- streaming is now done via AudioEngine.

## 1.0.0
* chore: Initial stable release.

Expand Down
31 changes: 26 additions & 5 deletions record_darwin/darwin/Classes/RecordConfig.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
enum AudioEncoder: String {
public enum AudioEncoder: String {
case aacLc = "aacLc"
case aacEld = "aacEld"
case aacHe = "aacHe"
Expand All @@ -10,13 +10,12 @@ enum AudioEncoder: String {
case wav = "wav"
}


class RecordConfig {
public class RecordConfig {
let encoder: String
let bitRate: Int
let sampleRate: Int
let numChannels: Int
let device: [String: Any]?
let device: Device?
let autoGain: Bool
let echoCancel: Bool
let noiseSuppress: Bool
Expand All @@ -25,7 +24,7 @@ class RecordConfig {
bitRate: Int,
sampleRate: Int,
numChannels: Int,
device: [String : Any]? = nil,
device: Device? = nil,
autoGain: Bool = false,
echoCancel: Bool = false,
noiseSuppress: Bool = false
Expand All @@ -40,3 +39,25 @@ class RecordConfig {
self.noiseSuppress = noiseSuppress
}
}

public class Device {
let id: String
let label: String

init(id: String, label: String) {
self.id = id
self.label = label
}

init(map: [String: Any]) {
self.id = map["id"] as! String
self.label = map["label"] as! String
}

func toMap() -> [String: Any] {
return [
"id": id,
"label": label
]
}
}
Loading

0 comments on commit c4ea8d1

Please sign in to comment.