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

Problems with Audio Streams on Mac OS #336

Closed
ihdream72 opened this issue Jun 4, 2024 · 2 comments
Closed

Problems with Audio Streams on Mac OS #336

ihdream72 opened this issue Jun 4, 2024 · 2 comments

Comments

@ihdream72
Copy link
Contributor

ihdream72 commented Jun 4, 2024

Package version
5.1.1

Environment

  • OS: [ Macos ]

I am developing a service where I want to record stream audio from multiple platforms and use Google's Speech to Text service.

const RecordConfig config = RecordConfig(
  encoder: AudioEncoder.pcm16bits,
  sampleRate: 16000,
  numChannels: 1,
);

Stream<Uint8List>? stream = await recorder?.startStream(config);

streamSubscription = stream?.listen((chunk) async {
  Log.d('MACOS PCM => [${DateTime.now()}] ${chunk.length}');
  onStream(chunk);
});

Recording as above works fine on Android, but not on MacOS.
If you look at the logs left behind on MacOS, you'll see the following

flutter: [⭐️] MACOS PCM => [2024-06-04 14:23:10.071288] 1600
flutter: [⭐️] MACOS PCM => [2024-06-04 14:23:10.178055] 1600
flutter: [⭐️] MACOS PCM => [2024-06-04 14:23:10.275184] 1600
flutter: [⭐️] MACOS PCM => [2024-06-04 14:23:10.381623] 1600

  • PCM16 Format / 16000 sampleRate => 36000 byte per 1 sec
    However, the logs show that only 1600 bytes come through every 0.1 seconds, or 16000 bytes per second.

Can you confirm this issue?

�I appreciates the your effort.

@ihdream72
Copy link
Contributor Author

ihdream72 commented Jun 4, 2024

I made the following modifications to the 'record_darwin/darwin/Classes/delegate/RecorderStreamDelegate.swift' file
I did that and it works fine on MacOS.
Please check it out and let me know if you can update it.

private func stream(
    buffer: AVAudioPCMBuffer,
    dstFormat: AVAudioFormat,
    converter: AVAudioConverter,
    recordEventHandler: RecordStreamHandler
  ) -> Void {
   
   ...
   ... 
    // Determine frame capacity
    // let capacity = (UInt32(dstFormat.sampleRate) * dstFormat.channelCount * buffer.frameLength) / (UInt32(buffer.format.sampleRate) * buffer.format.channelCount)
  
       let capacity = (UInt32(dstFormat.sampleRate) * dstFormat.channelCount * buffer.frameLength * 2) / (UInt32(buffer.format.sampleRate) * buffer.format.channelCount)

     ...
     ...
    
  }

@llfbandit
Copy link
Owner

Thanks, can you fill a PR for this?
Also, it should be tested on iOS since this code is shared between the platforms.

ihdream72 added a commit to ihdream72/record that referenced this issue Jun 4, 2024
Incorrect buffer size for sending Streams and increasing the size
llfbandit pushed a commit that referenced this issue Jun 7, 2024
Incorrect buffer size for sending Streams and increasing the size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants