Skip to content

[iOS] No Audio Input When Streaming Through Headphones #451

@Goolpe

Description

@Goolpe

Package version
^5.2.0

Environment

  • OS: iOS
  • Tested on airpods 3 and pro 2, iPhone 11

Describe the bug

When recording audio through headphones, no sound is produced. Instead, the following data is received:
[0, 8, 254, 232, 68, 0, 0, 0, 0, 0, 0, 0, ... zeros ..., 0].

To Reproduce

Steps to reproduce the behavior:

  1. Copy and paste the code
  2. Run the app on iOS
  3. Connect headphones (airpods)
  4. Press start and try to say something
  5. Press stop
  6. Disconnect headphones and try again
import 'package:flutter/material.dart';
import 'package:record/record.dart';

void main() {
  runApp(_App());
}

class _App extends StatelessWidget {
  const _App({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: _TestRecorder(),
    );
  }
}

class _TestRecorder extends StatefulWidget {
  const _TestRecorder({super.key});

  @override
  State<_TestRecorder> createState() => _TestRecorderState();
}

class _TestRecorderState extends State<_TestRecorder> {
  final _recorder = AudioRecorder();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () async {
                final stream = await _recorder
                    .startStream(const RecordConfig(encoder: AudioEncoder.pcm16bits));

                stream.listen((data) {
                  print('DATA: ${data.buffer.asUint8List()}');
                });
              },
              child: const Text('START'),
            ),
            ElevatedButton(
              onPressed: () async {
                await _recorder.stop();
              },
              child: const Text('STOP'),
            ),
          ],
        ),
      ),
    );
  }
}

Expected behavior

Audio should be recorded through the connected headphones.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions