csdcorp / speech_to_text

A Flutter plugin that exposes device specific text to speech recognition capability.
BSD 3-Clause "New" or "Revised" License
351 stars 218 forks source link

Wireless headsets support #210

Closed rayrapetyan closed 2 years ago

rayrapetyan commented 3 years ago

Hello. It would be nice to have a support for a wireless headsets (currently only default device's microphone is utilized).

At least for Android it should be as simple as adding few lines of code:

https://stackoverflow.com/questions/28086403/android-speech-recognizer-with-bluetooth-microphone https://stackoverflow.com/questions/8681085/android-voice-recognition-through-bluetooth

I haven't tried them though.

The question is if it's also easy to do the same on iOS.

Thanks.

sowens-csd commented 3 years ago

AFAIK wired headsets already work fine because they become the default when plugged in. I've definitely used them on iOS though not on Android. Have you tried it? I

I haven't tried Bluetooth. I guess that you did and it doesn't work? Did you try on both Android and iOS?

rayrapetyan commented 3 years ago

Thanks Stephen! Just curious - how did you test wired headset, I mean when it's plugged in your phone is nearby anyway, so how do you know headset's mic (and not the built-in microphone) was used?

I tried BT on Android and yeah, it doesn't work. My BT mic doesn't work even on the in-system voice input (e.g. when you use mic on a standard google keyboard voice input). It works (and turns on automatically) only on incoming call (in any app supporting calls). I think this is all by design and that's how it's expected to work. At the same time I'm sure BT mic can be turned on explicitly (using steps from links above).

rayrapetyan commented 3 years ago

There is one thing I'm afraid will not work though... Every time I test my mic at e.g. https://mictests.com/, I can hear "Call ended" at the end of test. So if it's a hardware feature, it might be hard to disable programmatically (if at all possible).

rayrapetyan commented 3 years ago

UPD: I've just tested a wired headset and mic becomes default, I've scratched the mic while recording so I'm 100% sure it works. Tried few more BT - none of them work with this plugin. Also, not all BT say "call ended" at https://mictests.com, so I think it's configurable from the headsets supporting tools\apps.

sylvainjack commented 2 years ago

Hi everyone, I encountered the same problem with apple AIRPODS : speech to text didn't work. In the same app, I use tts_ (text to speech) and had the same problem. The sound wouldn't go through the AirPods. Apparently, I found this on the flutter_tts package (text to speech) : await flutterTts .setIosAudioCategory(IosTextToSpeechAudioCategory.playAndRecord, [ IosTextToSpeechAudioCategoryOptions.allowBluetooth, IosTextToSpeechAudioCategoryOptions.allowBluetoothA2DP, IosTextToSpeechAudioCategoryOptions.mixWithOthers ]);

This actually solved the problem for TEXT TO SPEECH and the SPEECH TO TEXT packages. Both now work on my iPhone. Haven't tested it on Android.

sowens-csd commented 2 years ago

Current state of this is that @sylvainjack's suggested fix is released os Bluetooth should be working on iOS. The Android version needs updates to properly support Bluetooth.

sowens-csd commented 2 years ago

Android support for bluetooth is now in the repo version. If anyone has a chance to test it that would be welcome. I've tried it on a Samsung with headphones and it seems to be working.

rayrapetyan commented 2 years ago

Thanks, tested it today. By itself it works fine, but when https://pub.dev/packages/text_to_speech is also used, occasionally output voice becomes muted (you can't hear anything in headphones nor from speaker). Calling "setVolume" right before "speak" doesn't help. What could be the reason?

sowens-csd commented 2 years ago

Thanks for testing it so quickly. Does the volume issue only happen if you are using a Bluetooth device or does it happen even if you have bluetooth turned off completely?

rayrapetyan commented 2 years ago

Only when Bluetooth device is connected and used.

sowens-csd commented 2 years ago

Thanks, I'll try to reproduce and see what I can do. In general volume issues on Android are painful.

sowens-csd commented 2 years ago

I think I have a reproduce but for me it is happening every second phrase. So I start a listen, then use speak to play back what I just said. The first time it works properly, the second time it is either very low volume or not working at all, not sure which. That pattern then repeats. Do you see the same behaviour or different?

rayrapetyan commented 2 years ago

Exactly! Every second phrase is muted. I've tried SetVolume before each phrase and it didn't help.

sowens-csd commented 2 years ago

Excellent, glad yours is the same.

Okay, I've just committed a potential fix. It resolves the issue for me. I was only stopping the bluetooth headset on an explicit stop or cancel. This version stops it every time speech ends. Let me know if this works for you.

rayrapetyan commented 2 years ago

It works now, thanks!

sowens-csd commented 2 years ago

This is published as 5.4.0 on pub.dev. Thanks for the help verifying this!