speak to bluetooth

635 views
Skip to first unread message

booga...@gmail.com

unread,
Feb 13, 2015, 2:34:48 PM2/13/15
to automa...@googlegroups.com
On my fiber I want to receive an sms and then speak it so the sound comes through my connected bluetooth device. No matter what audio channel I pick the sound will always come from the phone. What am I missing?

Automate developer

unread,
Feb 13, 2015, 7:18:10 PM2/13/15
to automa...@googlegroups.com, booga...@gmail.com
You probably have a mono headset that only support the SCO protocol. The SCO protocol is only capable of low bit-rate voice audio.

However Android do allow apps to route audio through SCO, but for some reason, it has to be enabled first. I dont have a SCO BT headset myself, so i cant really test it, but i'll add a block to enable SCO in the next release.

Some other apps that enable SCO, in the same way Automate will:
https://play.google.com/store/apps/details?id=com.bedoig.BTmono
https://play.google.com/store/apps/details?id=com.turboled.audiobt
https://play.google.com/store/apps/details?id=js.android.btmusic

booga...@gmail.com

unread,
Feb 21, 2015, 10:57:25 PM2/21/15
to automa...@googlegroups.com
You are right, it's a Motorola hands-free set in my car and it is mono indeed. Looking forward to your update.

In the mean time I checked a few of the mono routers like BTMono. I use a Start app block before I use the speak block and the sound will indeed come from the hands-free. However after this I try to kill the app again and that fails. It's not that the block throws an error but the app does not disappear.
I realize the documentation says the option is to kill a background app and the app I just started is in the foreground. Or do I need a rooted phone to kill an app?

Any insight you can give is appreciated.

Automate developer

unread,
Feb 21, 2015, 11:52:52 PM2/21/15
to automa...@googlegroups.com, booga...@gmail.com
I'll try to release the new Alpha tomorrow (Sunday), it will have a block to route audio through SCO.

I've also added a new App kill block for rooted devices, to terminate the whole app. But if the SCO block works you wont need it.
The current App kill block, for non-rooted devices, can only kill background services.

Since i don't have a SCO headset myself i'll appreciate your help with testing the new SCO block.

booga...@gmail.com

unread,
Feb 25, 2015, 8:19:24 PM2/25/15
to automa...@googlegroups.com
Thanks. I tried the SCO block with a Plantronics 320 headset and a Motorola T325 handsfree set. Both seem to act the same way.
On the SCO connect you hear a little beep, similar to the beep I heard when I tried out the BTmono application.
I tried to speak the message through the System audio channel which worked with BTmono before but now the sound came from the phone speaker.
After some experimenting I found that from all the audio channels only the Voice call option works through the bluetooth devices.
For me this is sufficient as I won't need an extra app anymore. Not sure however if you expected it to work through all channels.

Automate developer

unread,
Feb 25, 2015, 8:59:31 PM2/25/15
to automa...@googlegroups.com, booga...@gmail.com
Thanks for testing!

Yes there's some restrictions, only the Voice call stream can be used, must be mono, sample rate must be 8kHz or 16kHz:
http://developer.android.com/reference/android/media/AudioManager.html#startBluetoothSco%28%29
I'll include the restrictions in the block documentation.

Did you try the "Reenable after call", it should reconnect and keep SCO enabled even after a call goes off-hook?

The Bluetooth SCO block works like the Device keep awake and Screen lock block, so you should do like this:
          :
   Enable Bluetooth SCO
          |
        Speak
 or any other sound block
          |
  Disable Bluetooth SCO
          :

booga...@gmail.com

unread,
Feb 25, 2015, 10:23:58 PM2/25/15
to automa...@googlegroups.com
The way my program goes right now is that when I receive a text message I switch on SCO and speak the message and then switch SCO off again. Then loop back.
So testing the Reenable function I need to change so that SCO is on from the beginning and essentially not switch off until I disconnect from the bluetooth. Then when receiving a call I will check if the messaging afterwards works still. I'll let you know.

In my scenario I ran into a problem however. I was on a call, then received a text, on which SCO was activated. This caused a crash and stopped the fiber. The error in the log was:
java.lang.IllegalStateException: Failed establish Bluetooth SCO connection
What do I need to do to check? Or is this something you can fix inside the program?

Automate developer

unread,
Feb 25, 2015, 11:05:35 PM2/25/15
to automa...@googlegroups.com, booga...@gmail.com
To test the reenable function use a simple flow like this:

    Flow Beginning
          |
   Enable Bluetooth SCO
   Reenable after call
          |
      Delay 3m
          |
        Speak
       "Hello"
   
stream: Voice call

If you then make an outgoing, or take an incoming call during the delay and hang up, the Speak block should still be heard through the headset.

The error. It may be that SCO can't be enabled during a call, i'll add a check for it.
I'll add some debug logging to the next release so we can see what's going on.

Thanks for helping.

booga...@gmail.com

unread,
Feb 26, 2015, 11:18:19 PM2/26/15
to automa...@googlegroups.com
Ok. I tested this and it does not seem to work. If I don't make a call during the delay the sound will come through the headset. But if I accept a call then after that the sound comes from the phone speaker.
I thought maybe you have the logic reversed, so I unchecked the "Reenable after call" but that didn't work either.
Not sure if that's enough info for you, but I'll be happy to try out anything you want.

Automate developer

unread,
Feb 26, 2015, 11:38:37 PM2/26/15
to automa...@googlegroups.com, booga...@gmail.com
Thanks for helping. I've made some changes, hopefully even the "Reenable" will work in the next Alpha release.

Automate developer

unread,
Mar 1, 2015, 2:48:10 PM3/1/15
to automa...@googlegroups.com, booga...@gmail.com
Please try the new Alpha version 1.0.11, i've made some changes.
Enable the "Extended debug logging" in Settings, then the flow log will contain additional information that will help in fixing any new issues.


On Friday, February 27, 2015 at 5:18:19 AM UTC+1, booga...@gmail.com wrote:

booga...@gmail.com

unread,
Mar 1, 2015, 4:23:09 PM3/1/15
to automa...@googlegroups.com
Ok. The flow enables SCO with reenable switched on, then goes in delay for 1 minute. Within that minute I call and and the call. After that I speak the message and the sound does not come through the bluetooth. Than I switch off SCO and speak another text that should come through phone speaker. Since both texts came through the phone speaker its not right yet. Below the debug log.

2015-03-01 16:11:58.658 INFO 97@1: Flow beginning
2015-03-01 16:11:58.659 INFO 97@2: Bluetooth SCO
2015-03-01 16:11:58.951 DBUG 97@2: BluetoothSco ACTION_SCO_AUDIO_STATE_UPDATED: connected
2015-03-01 16:11:58.953 INFO 97@3: Delay
2015-03-01 16:12:18.822 DBUG 97@2: BluetoothSco ACTION_SCO_AUDIO_STATE_UPDATED: disconnected
2015-03-01 16:12:18.881 DBUG 97@2: BluetoothSco startBluetoothSco: skip, still in call
2015-03-01 16:12:28.590 DBUG 97@2: BluetoothSco ACTION_PHONE_STATE_CHANGED: idle
2015-03-01 16:12:28.653 DBUG 97@2: BluetoothSco ACTION_SCO_AUDIO_STATE_UPDATED: disconnected
2015-03-01 16:12:58.961 INFO 97@4: Speak
2015-03-01 16:13:00.110 INFO 97@5: Bluetooth SCO
2015-03-01 16:13:00.116 INFO 97@6: Speak
2015-03-01 16:13:01.372 INFO 97@0: Stopped at end

booga...@gmail.com

unread,
Mar 1, 2015, 4:29:08 PM3/1/15
to automa...@googlegroups.com
See below a successful session if I don't call during the delay. The first text comes indeed through the bluetooth.

2015-03-01 16:25:57.776 INFO 100@1: Flow beginning
2015-03-01 16:25:57.779 INFO 100@2: Bluetooth SCO
2015-03-01 16:25:57.967 DBUG 100@2: BluetoothSco ACTION_SCO_AUDIO_STATE_UPDATED: connected
2015-03-01 16:25:57.970 INFO 100@3: Delay
2015-03-01 16:26:57.988 INFO 100@4: Speak
2015-03-01 16:26:59.377 INFO 100@5: Bluetooth SCO
2015-03-01 16:26:59.401 INFO 100@6: Speak
2015-03-01 16:27:00.831 INFO 100@0: Stopped at end

Automate developer

unread,
Mar 1, 2015, 5:59:02 PM3/1/15
to automa...@googlegroups.com, booga...@gmail.com
Thanks for the log, very informative.

At least the block sees that SCO disconnects and that the call ends. It tries to reenable SCO at:

2015-03-01 16:12:28.590 DBUG 97@2: BluetoothSco ACTION_PHONE_STATE_CHANGED: idle

...and at:

2015-03-01 16:12:28.653 DBUG 97@2: BluetoothSco ACTION_SCO_AUDIO_STATE_UPDATED: disconnected

...but for whatever reason it can't connect, or you would see a:
ACTION_SCO_AUDIO_STATE_UPDATED: connected

I'll have to investigate further, it may be an Android bug. I will add even more debug logging that could help us solve the issue.

booga...@gmail.com

unread,
Mar 7, 2015, 5:02:53 PM3/7/15
to automa...@googlegroups.com
Ok. Tried now with version 1.0.13.
Here is the debug log:
2015-03-07 16:53:48.008 INFO 110@1: Flow beginning
2015-03-07 16:53:48.016 INFO 110@2: Bluetooth SCO
2015-03-07 16:53:48.217 DBUG 110@2: BluetoothSco ACTION_SCO_AUDIO_STATE_UPDATED: connected
2015-03-07 16:53:48.221 INFO 110@3: Delay
2015-03-07 16:54:13.261 DBUG 110@2: BluetoothSco ACTION_PHONE_STATE_CHANGED: RINGING
2015-03-07 16:54:13.560 DBUG 110@2: BluetoothSco ACTION_SCO_AUDIO_STATE_UPDATED: disconnected
2015-03-07 16:54:13.567 DBUG 110@2: BluetoothSco startBluetoothSco
2015-03-07 16:54:18.233 DBUG 110@2: BluetoothSco ACTION_PHONE_STATE_CHANGED: OFFHOOK
2015-03-07 16:54:23.622 DBUG 110@2: BluetoothSco ACTION_PHONE_STATE_CHANGED: IDLE
2015-03-07 16:54:23.623 DBUG 110@2: BluetoothSco startBluetoothSco
2015-03-07 16:54:23.801 DBUG 110@2: BluetoothSco ACTION_SCO_AUDIO_STATE_UPDATED: disconnected
2015-03-07 16:54:23.805 DBUG 110@2: BluetoothSco startBluetoothSco
2015-03-07 16:54:48.236 INFO 110@4: Speak
2015-03-07 16:54:49.497 INFO 110@5: Bluetooth SCO
2015-03-07 16:54:49.521 INFO 110@6: Speak
2015-03-07 16:54:50.803 INFO 110@0: Stopped at end

The first speak still does not come through the bluetooth. What is worse, it seems the SCO is now in some weird state. If I run the fiber again it hangs on the enable SCO. It never goes past it. No error message in the log.
I have to disable bluetooth on the phone and enable it again to get control again.

Automate developer

unread,
Mar 7, 2015, 7:05:28 PM3/7/15
to automa...@googlegroups.com, booga...@gmail.com
Seems like every time SCO has been disconnected after a call state change, and the block tries to re-start it again, it always gets disconnected to indicating it can't connect.

If SCO isn't connected the block will wait for a ACTION_SCO_AUDIO_STATE_UPDATED to be successful connected, or disconnected and fail.

We now know what's failing, the reconnecting bit. It's probably an Android issue, where it's not reporting the correct "connected" state or not doing proper "cleanup" leaving SCO in a invalid state.
I'll look for an fix, having to disable and re-enabling the Bluetooth isn't an option.

You should be able to use the block without "re-enable after call", and hope a call doesn't occur when it's active messing up its state.

emp...@gmail.com

unread,
Jun 3, 2015, 9:06:36 AM6/3/15
to automa...@googlegroups.com, booga...@gmail.com
Hi.
At first thanks for your awesome app.

I'm trying to make flow that will speak name of calling contact and accept or reject call after voice command. Everything works good. But when i connect bluetooth handsfree (sony mw600) all sound goes through phone or media speaker. If i accept or reject call manually and flow still active because of retrying voice recognition sound start to go through handsfree. If i Speak something without active call - everything is ok, Speak comes through handsfree. SCO didn't help me. Maybe it's android or my phone(sony z3c) bug, but symptoms are very similar to booga.

воскресенье, 8 марта 2015 г., 3:05:28 UTC+3 пользователь Automate developer написал:

Automate developer

unread,
Jun 3, 2015, 2:27:30 PM6/3/15
to automa...@googlegroups.com, emp...@gmail.com, booga...@gmail.com, emp...@gmail.com
Whether the sound are routed through the speaker or headset are controlled by SCO for mono Bluetooth headsets.
The Bluetooth SCO block just enables or disabled it, basically a single line of code. The problem is keeping SCO enabled, any app, like the default dialer, can disable it at any time, usually after the phone call.

Many apps controlling SCO has problems, so i think it's likely poorly implemented in Android.

emp...@gmail.com

unread,
Jun 4, 2015, 7:31:35 AM6/4/15
to automa...@googlegroups.com, emp...@gmail.com, booga...@gmail.com
Thank you for answer. Yesterday i tried a lot of routing apps, different combinations of streams. at this point i think that i should try to change dialer or update my phone to 5.0 or buy wired handsfree. also i think that problem is near internal ringer melody of handsfree. maybe it hold focus. Obviously problem is not in the Automate.

среда, 3 июня 2015 г., 21:27:30 UTC+3 пользователь Automate developer написал:

Automate developer

unread,
Jun 4, 2015, 2:15:16 PM6/4/15
to automa...@googlegroups.com, emp...@gmail.com, emp...@gmail.com, booga...@gmail.com
SCO only supports 8kHz or 16kHz mono playback.
This could also prevent certain sounds from being heard.

I know that the "Reenabled after call" option in the Bluetooth SCO block probably are buggy.
To help me fix the issue, enable the "Debug logging" in settings, then send me the flow log file.
Reply all
Reply to author
Forward
0 new messages