osmandapp / OsmAnd

OsmAnd
https://osmand.net
Other
4.72k stars 1.03k forks source link

No Voice / Audio while Listening to music #5488

Open dr2okevin opened 6 years ago

dr2okevin commented 6 years ago

I use osmAnd+ on my car Headunit (Ownice c500). This Headunit has FM Radio. My Problem ist that every time I listen to the radio, osmAnd dosen't gives my any sound. This ist not a Hardware issues, becaus Google Maps or Skobbler for example, don't have this issue.

So far I can see the difference is what kind of Audio is used. Using the channel "Music" or "Notfication" dosn't work, but the channel "Navigation" works. Unfortinally I cant Change this in osmand.

Here is a Pic of the system settings for the Volume https://chinagadgets.net/wp-content/uploads/2017/09/2017-08-31-11.53.04.jpg

sonora commented 6 years ago

Have you tried all 3 available options under "Settings/Navigation/Voice guidance output"?

The first one should produce the OsmAnd prompts as if they were media/music files, the second uses the ringtone channel, and the third one essentially emulates an incoming phone call, which works in the situations where you connect your device as phone to a car FM system. I am not aware Android offers any more available channels, your picture showing a volume setting for a "Navigation" channel may be hardware specific or Androd version specific, not sure...

dr2okevin commented 6 years ago

I tried all 3. None of them worked. But they work all if one of the other mentioned apps sends a voice signal at the same time.

sonora commented 6 years ago

I assume you have also toggled the 'Interrupt music' setting to no avail?

It sounds like the FM mode in that device ignores all other sound output unless a certain trigger is sent, maybe the indication for a traffic announcement (TA) or similar, but I have no idea how to achieve that programmatically. Maybe someone else reading this has an idea what Android feature we could test here.

It baffles me that 2 other apps work without issues. Did they come pre-installed, or did you add them from the Play store? If we find an open source app (not necessarily navigation related) which produces sound interrupting your FM radio we could look at the code.

sonora commented 6 years ago

For what it's worth: I just tested on a Samsung S4 Mini which has a built-in FM chip: OsmAnd's navigation prompts do correctly interrupt both music played from the built-in FM radio app as well as MP3 music played via Android's music player.

This works regardless which audio output channel (music, notification, phone call) is selected for OsmAnd (which essentially determines via which speaker you hear its sound). So this is really hardware dependent, and it remains to be researched by what method FM radio can be interrupted on your particular device.

From all I know Android per se does not offer a 'Navigation' audio output channel, your device having a volume setting for that seems to be something rather specific.

dr2okevin commented 6 years ago

I have created a video this morning to show what works and what not. https://www.kevinquiatkowski.de/MOV_1669.mp4

Currently the following apps are working Google Maps (Play Store) Scout (Play Store) iGo (Preinstalled)

I will test some more apps

dr2okevin commented 6 years ago

I now tested the following apps. MapFactor GPS Navigation Maps (Play Store, voice works) blitzer.de (Play Store, voice dosn't work)

dr2okevin commented 5 years ago

I still have this Issue. Is there anything I can do to help?

dr2okevin commented 5 years ago

One year later. problem still exists.

dr2okevin commented 5 years ago

Just some hints I have serval volume Controls. Beside the default ones I Have also Bluetoth, Navigation and System. image

That matches pretty good with the volume groups that should be available in android 9 (strange, I have android 6) https://source.android.com/devices/automotive/audio#volume-and-groups

there is also a Doc that describes USAGE_ASSISTANCE_NAVIGATION_GUIDANCE https://source.android.com/devices/audio/attributes#contexts

And also some code that is way older than android 9 and has also some navigation specific stuff https://android.googlesource.com/platform/packages/services/Car/+/nougat-mr1-dev/service/src/com/android/car/CarAudioAttributesUtil.java

And as already mentioned on twitter, I'm willing to pay money to fix this bug.

Edit: Google maps probably uses USAGE_ASSISTANCE_NAVIGATION_GUIDANCE https://stackoverflow.com/a/54708039/2482579

vshcherb commented 5 years ago

We are using this constants to play audio files https://developer.android.com/reference/android/media/AudioManager.html#STREAM_ALARM (We didn't specify in settings STREAM_DTMF, STREAM_ALARM, STREAM_ACCESSIBILITY, STREAM_NOTIFICATION, STREAM_RING cause they are clearly wrong). We need to specify 1 of these constants cause it is used https://developer.android.com/reference/android/media/MediaPlayer.html#setAudioStreamType(int)

I added a new "DEFAULT" type (https://github.com/osmandapp/Osmand/commit/2aee7e6b41c986411d127f3fca3a53fecf85e03a) give it a try with nightly build https://download.osmand.net/latest-night-build/OsmAnd-nightly.apk.

vshcherb commented 5 years ago

I see its method was deprecated and now it is even more confusing https://developer.android.com/reference/android/media/AudioAttributes.html?hl=en

This is I think offtopic - https://source.android.com/devices/automotive/audio#volume-and-groups cause it is about Google Car I think

dr2okevin commented 5 years ago

I'm not a Android Developer, but as far as I understand there is a Stream Type and a Stream Usage that can be set simultaneous STREAM_ALARM is the type USAGE_ASSISTANCE_NAVIGATION_GUIDANCE would be the usage. I guess my Device watches also for the usage.

Update: The Nightly with sound setting default does not work.

vshcherb commented 5 years ago

You are referencing to API and to answers which I actually don't know what it means. Probably I'm not good Android developer either but I have no device neither understanding.

Probably this is relevant

Android 9 includes the following changes to automotive-related audio support:

The Audio HAL Context maps to AudioAttributes.usage to identify sounds; the Audio HAL implementation is responsible for Context-specific mixing/routing.

https://developer.android.com/reference/android/media/AudioAttributes.html?hl=en#USAGE_ASSISTANCE_NAVIGATION_GUIDANCE

vshcherb commented 5 years ago

I think we are going to convert our code to AudioAttributes by 3.5 and lets if it helps.

svenofix commented 5 years ago

Hi!

I have a potential fix for this issue using AudioAttributes. https://github.com/svenofix/Osmand/commit/b1e958d5927b47567787e3578051d6d35a4cd061

I haven't had a chance to test this (haven't gotten the project to run yet, tests are failing). I'm also unsure if MediaCommandPlayerImpl benefits from those changes.

dr2okevin commented 5 years ago

@vshcherb can you make a test build with the changes from @svenofix ? Then I can test it.

vshcherb commented 5 years ago

Created PR https://github.com/osmandapp/Osmand/pull/7324

vshcherb commented 5 years ago

Give it a try with new build

dr2okevin commented 5 years ago

Unfortunately, the new version also don't work :(

sonora commented 5 years ago

@vshcherb I guess we should revert https://github.com/osmandapp/Osmand/commit/2aee7e6b41c986411d127f3fca3a53fecf85e03a ? I see no issue we had and is resolved by it, so it only further complicates the handling for the user?

https://github.com/osmandapp/Osmand/pull/7324 seems fine though, that was a needed upgrade to our code! Thx!

vshcherb commented 5 years ago

Well I think string is better to keep :) but option no need I think. It is strange that AudioAttributes didn't help

sonora commented 5 years ago

Yes, it was my plan exactly to try the AudioAttributes, but the PR was faster. Very strange it does not fix it. I am wondering what else to do, because I have tried all my devices and they all work fine, so I cannot reproduce.

dr2okevin commented 5 years ago

if you have something that could work, you can just send me the apk, and I will test it asap. In the meantime I have also send a mail to the manufacturer of my device, currently waiting for any response.

sonora commented 5 years ago

The AudioAttributes API introduced since level 21 features attributes for Usage, Content type, Context, and Flags, the latter also supporting things like FLAG_AUDIBILITY_ENFORCED.

I guess by playing with its full capability, we could solve this issue, but for me personally it would require a full deep dive into the documentation first.

dr2okevin commented 5 years ago

I have just updated with the newest nightly, and using prerecorded audio is working now. It also shows now navigation volume if I change it while the instructions are playing. But TTS is still not working, it has the same behavior than the old playstore version.

sonora commented 5 years ago

That's encouraging, I think it confirms Victor's and my suspicion that using setAudioAttributes should solve the issue. Looks like our implementation of it is still incomplete for the TTS case. I have made a slight change, but it may not fix it yet.

setAudioStreamType is deprecated from API Level 26, we should completely convert our code to just use AudioAttributes for API>=21. Will make a PR.

Mapping to apply:

Also deprecated are and requestAudioFocus (AudioManager.OnAudioFocusChangeListener l, int streamType, int durationHint) and abandonAudioFocus. May have to tackle this also, for API >= 26. Reference: https://developer.android.com/guide/topics/media-apps/audio-focus

sonora commented 5 years ago

I have replaced all setAudioStreamType above API 21, see https://github.com/osmandapp/Osmand/commit/6c4fc659af680163cc0a2ceb8d4a847d28b2c736. It works by my testing..

@dr2okevin Can you please test now? Does it really only work for recorded and not TTS voices?

@vshcherb At some point we may want to look into also replacing the deprecated requestAudioFocus and abandonAudioFocus, but from what I see, this would only affect API 26 and up, see https://developer.android.com/guide/topics/media-apps/audio-focus

dr2okevin commented 5 years ago

I have now tested again. Still only recorded sound, no TTS when I turn off the radio, the recorded voice has the navigation volume control, while the TTS still has the media/music volume control.

sonora commented 5 years ago

That sounds like setting the usage audio attribute to Navigation works for the media player but not for the tts engine (or it is somehow overwritten). I cutrently find no flaw in the code.

My Android 6 device uses the Media volume in both cases, so not reproducible there. Will have to check on an Android 9 next week to see if I find any hints.

PS: When you use the Notification or Phone call output, which volume sliders are used then for both the media and the tts cases?

dr2okevin commented 5 years ago

If I select Bluetooth, I don't get any sound at all, even when the radio is off. Volume Sliders are then Media. Notification or Media doesn't matter, they behave both exactly the same on my device.

sonora commented 5 years ago

I am talking the 3 different options available under OsmAnd's Navigation settings / Voice guidance output. No need to connect any BT device for the test. I am just wondering which volume gets changed (usually shown in an on-screen popup) when using the device's hardware volume buttons during an OsmAnd announcement with, each of the 3 settings and both for a recorded voice and a tts voice.

To test it is sufficient to use the Test voice prompts entry under OsmAnd's development plugin settings, which may be easier than performing an actual navigation.

dr2okevin commented 5 years ago

I have made a new Video https://www.kevinquiatkowski.de/GOPR5920.MP4

sonora commented 5 years ago

In summary: Looks to me like

But I am not 100% convinced that the volume bar your device suggests is in all cases the correct one to be used: In which of these cases does turning the volume knob during an OsmAnd prompt actually also truely change the audible volume? Perhaps only in the "TTS voice via Media" and "Recorded voice via Media" cases?

dr2okevin commented 5 years ago

The Bluetooth option behaves very wired, and the volume change dose not work there. Sometimes there isn't any sound at all. The Notification and the Music option have no difference in their working. TTS = Media volume bar (working), but no audio when radio on. Recorded = Navigation volume bar (working), and audio even when the radio is on.

sonora commented 5 years ago

We are using the deprecated method setVolumeControlStream to assign the volume setting, but that should not cause the issue here.

So the question remains why addressing the Navi-volume only functions for the Media player and not the TTS player on your device. I have currently no idea what more to do in our code, but will keep looking.

PS: I have just reviewed your older movie again: Judging by the sound, it looks like all other apps you reported as "working" may be apps using recorded words, not TTS?

dr2okevin commented 5 years ago

I have just retested Google Maps, and it is saying the road names. So I would guess that they use TTS

sonora commented 5 years ago

Ok, thanks! So there's got to be a way somehow! :) I'll keep looking into this as I find time.

sonora commented 5 years ago

There is one more set of options you could try: Go to your device's (not OsmAnd) Text-to-speech options, and check if the language matches. Also check if there is an alternative engine to select, or if not, test and install a second one from the Play store. Occasionally I have heard people having one or the other issue with some tts engines.

sonora commented 5 years ago

I have now tested a Samsung Android 9 device, it works as ecpected after my recent commits to convert to AidioAttributes, so it looks like the code is fine on standard devices.

dr2okevin commented 5 years ago

Is there any new code that I can test?

sonora commented 5 years ago

Unfortunately not. Our nightly of 2019-07-28 contains my latest code on the issue, which seems to work as expected on all devices I have tested from Android 4.1 all the way to Android 9.

I currently have no idea why the implementation on your device seems to work only for recorded but not for TTS voices.

vshcherb commented 5 years ago

Don't forget Google Maps use own TTS engine (likely) and TTS-engine itself could be misconfigured (but I'm not sure) or require special parameters which we don't know yet.

BTW you can Test with Development plugin and Test Voice Prompts

sonora commented 5 years ago

Exactly. That's why I would be interested in @dr2okevin checking/testing this: https://github.com/osmandapp/Osmand/issues/5488#issuecomment-515790747

dr2okevin commented 5 years ago

I'm not sure what I should test. TTS in general is working fine. No matter what language I select. It is also working in osmAnd. But I get always the media volume. Navigation volume only on prerecorded. Google has also navigation volume on TTS.

sonora commented 5 years ago

It's just an idea, but maybe test another TTS engine. Some devices come with 2 pre-installed ones anyway (often google's and the device manufacturer's). And/or try one from the Play Store, like IVONA and others.

dr2okevin commented 5 years ago

I have tested it yesterday with pico tts and serval languages and voices. Always the same Result. Only the default/media volume bar visible, and so no sound when the radio ist on. But the nightly introduced a new bug. Route recalculation in a loop.

sonora commented 3 years ago

Worth re-testing with latest nightly.

sonora commented 2 years ago

@dr2okevin Worth re-testing with latest nightly, respectively upcoming release 4.3.

Should you not have that setup any more, could you please comment here, then we should close the issue as we have no way to reproduce.