Closed krit-l closed 3 years ago
This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.
Keep this issue open
@krit-l : I found a bug which can explain why you have difficulties to select the audio-device on iOS. I am going to fix that, and I will release a new version in a few days.
Please re-open this issue if you have still problems
I'm facing same issue in flutter android app, can you suggest any solution?
I have the same issue for android, i cant use Bluetooth mic for input. The app switches to built-in mic for audio input. Can you try to help me out here? Link to my problem : https://stackoverflow.com/questions/75637854/how-can-i-use-bluetooth-mic-in-flutter
I have the same issue for android, i cant use Bluetooth mic for input. The app switches to built-in mic for audio input. Can you try to help me out here? Link to my problem : https://stackoverflow.com/questions/75637854/how-can-i-use-bluetooth-mic-in-flutter
@Kashif-Asghar60 I resolved this issue by using Flutter channel to turn call mode on when Bluetooth is connected for recording.
Add this code into your kotlin file and call this channel from flutter
import android.annotation.SuppressLint import android.bluetooth.BluetoothAdapter import android.bluetooth.BluetoothClass import android.bluetooth.BluetoothDevice import android.content.Context import android.media.AudioManager import androidx.annotation.NonNull import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.engine.FlutterEngine import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
// Register a new method channel to communicate with the Flutter app
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "example.com/channel").setMethodCallHandler { call, result ->
when (call.method) {
"switchToBluetoothMicrophone" -> {
switchToBluetoothMicrophone()
result.success(null)
}
else -> {
result.notImplemented()
}
}
}
}
@SuppressLint("MissingPermission")
private fun switchToBluetoothMicrophone() {
// Get the Bluetooth adapter
val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
print("message1");
// Ensure that Bluetooth is enabled on the device
if (bluetoothAdapter.isEnabled) {
// Get a list of paired Bluetooth devices
val pairedDevices: Set<BluetoothDevice> = bluetoothAdapter.bondedDevices
print("message2")
// Iterate over the list of paired devices and find the Bluetooth microphone
for (device in pairedDevices) {
print("message3")
// if (device.bluetoothClass.deviceClass == BluetoothClass.Device.AUDIO_VIDEO_MICROPHONE) { // print("message4") // Set the Bluetooth microphone as the default audio input device val audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager audioManager.mode = AudioManager.MODE_IN_CALL audioManager.isBluetoothScoOn = true audioManager.startBluetoothSco() audioManager.isMicrophoneMute = false audioManager.isSpeakerphoneOn = false break // } } } } }
I used the native approach with kotlin and it worked , Hats-off to zahid for sharing the kotlin code.
I used the native approach with kotlin and it worked , Hats-off to zahid for sharing the kotlin code.
how are you handling it from flutter side?
Drop your email , i will share the project file with you.
I used method channels to call it from kotlin
I used method channels to call it from kotlin
im doing the same but it still uses the phone mic instead of connected bluetooth device
Drop your email , i will share the project file with you.
sure that would be very helpful thank you so much. @anooravk@gmail.com
yea , i had a similar problem. i fixed it. But my solution only works for call quality audio via Bluetooth. I mean the sound which is playing via Bluetooth headset while using mic will be in low quality , not bassy (high quality)
that would work I only need to use Bluetooth mic with speech recognition
@Kashif-Asghar60 Could you share your code with me also? Struggling to get Bluetooth mic recording working in Flutter. sveinbjornt@gmail.com
sveinbjornt@gmail.com
Check your email for the file; I've just sent it.
@Kashif-Asghar60 Could you share your code with me also? Struggling to get Bluetooth mic recording working in Flutter. sveinbjornt@gmail.com
To me as well please, aryan.one0793@gmail.com
@Kashif-Asghar60 Could you share your code with me also? Struggling to get Bluetooth mic recording working in Flutter. sveinbjornt@gmail.com
To me as well please, aryan.one0793@gmail.com
shared!
I had great luck with this in my audio session initialization code using audio_session
:
if (Platform.isAndroid) {
// Configure support for Bluetooth headset on Android
AndroidAudioManager().startBluetoothSco();
AndroidAudioManager().setBluetoothScoOn(true);
}
@Kashif-Asghar60 Could you share please your code with me also? Struggling to get Bluetooth mic recording working in Flutter. correo.aog@gmail.com
@Kashif-Asghar60 I'd be happy if you shared your code with me as well av2558@gmail.com
@sveinbjornt I tried your solution. It does enable recording via bluetooth headset, but it activates bluetooth communication mode which is more suited for voice/video calls. I used it and after disposing the recorder got a notification from my headset "Call has ended". Not so good for user experience with a simple recording.
@Kashif-Asghar60 I'd be happy if you shared your code with me as well av2558@gmail.com
@sveinbjornt I tried your solution. It does enable recording via bluetooth headset, but it activates bluetooth communication mode which is more suited for voice/video calls. I used it and after disposing the recorder got a notification from my headset "Call has ended". Not so good for user experience with a simple recording.
My solution does the same, it captures the audio from the mic in call quality mode. And somehow i accidentally deleted the project file from my drive, so i cant share it anymore :(
I had great luck with this in my audio session initialization code using
audio_session
:if (Platform.isAndroid) { // Configure support for Bluetooth headset on Android AndroidAudioManager().startBluetoothSco(); AndroidAudioManager().setBluetoothScoOn(true); }
@sveinbjornt thank you for your Android code snippet. Do you have a suggestion on how to code this for iOS?
@sveinbjornt thank you for your Android code snippet. Do you have a suggestion on how to code this for iOS?
I never had any problems with Bluetooth audio recording on iOS.
@sveinbjornt did you have to setup flutter_sound for Bluetooth? My code to open the record from initState() is below but it still uses the iPhone microphone.
Future<void> openTheRecorder() async {
var status = await Permission.microphone.request();
if (status != PermissionStatus.granted) {
throw RecordingPermissionException('Microphone permission not granted');
}
// }
await _recorder.openAudioSession();
_mRecorderIsInited = true;
}
I need Help for : To record audio using a bluetooth microphone
Using the API ? Flutter_Sound 5.1.1 (Full)
Generate an iOS or Android App ? iOS (iPhone6s, iOS: 13.5.1) Android
Here is my question :
Hi,
I downloaded "flutter_sound" 5.1.1 and adjust the code in "demo1.dart" to change to "bluetootha2dp"
However, it does not work. It still capture the voice from the embedded microphone.
Then, I tried to OpenAudioSession
Still, it does not work.
Is there anything I missed? If anyone could guide me or provide a source code, would be very appreciated.
Sorry that I am totally new to Flutter and iOS.
Regards, Krit