Android Question Using SoundPool to make a sentence

Kevin Hartin

Member
Licensed User
Hi all, I have been hacking my way through building an app with offline maps, a database of markers and alerts as a marker comes near. It is all working fine as I post an alert to the screen with all the relevant information using ToastMessageShow.

What I want to add as an option is a verbal alert such as "Fuel 100 metres ahead". I have been playing around with a sample app and have stored "100", "Metres" and "Ahead" into a soundpool thing and want to play them back sequentially, one after the other.

Question is Should I use "Wait for" or am I better storing an array of Sleep values for each of the sound files?

I am really new to this sort of programming, so don't really understand what I am waiting for with respect to SP.Play

B4X:
Sub Button8_Click
    PlayId5 = SP.Play(LoadId5,  1, 1, 1, 0, 1)
    Sleep(1000)
    PlayId6 = SP.Play(LoadId6,  1, 1, 1, 0, 1)
    Sleep(600)
    PlayId7 = SP.Play(LoadId7,  1, 1, 1, 0, 1)
End Sub
Thanks in advance,
Kev
 

Attachments

emexes

Well-Known Member
Licensed User
Is there a reason for not using Text To Speech? I just gave it a quick burl, seems to work ok (even speaks "BP" and "7-Eleven" correctly).

I thought maybe you were wary of relying on a wireless data connection during mobile/vehicular use, but I just tested it here in airplane mode and with Wifi off, and it still speaks ok (although there is a slim chance that it caches recent TTS conversions, so... best test that a bit harder).

B4X:
Sub Process_Globals   
    Dim TTS1 As TTS
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")    'just a simple button (Button1)
End Sub

Sub TTS1_Ready (Success As Boolean)
    Log("TTS1_Ready " & Success)
   
    If Success = False Then
        Msgbox("Error initializing TTS engine.", "")
    End If
End Sub

Sub Activity_Resume
    If TTS1.IsInitialized = False Then
        TTS1.Initialize("TTS1")
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)   
    TTS1.Release
End Sub

Sub Button1_Click
    Log("Fuel ahoy!")
   
    TTS1.Speak("Fuel ahead in 100 metres.", False)
    TTS1.Speak("BP petrol station on left in 120 metres.", False)
    TTS1.Speak("7-Eleven petrol station ahead in 140 metres.", False)
    TTS1.Speak("Caltex petrol station on right in 234 metres.", False)
End Sub
 

Kevin Hartin

Member
Licensed User
Burl... Aussie, Aussie, Aussie

I didn't even know about text to speech, will have a crack tomorrow.

What voice/accents are used in this? Can those be changed? I thought that I might get s friendly Samoan voice to record the word bites I needed.

Kev
 

emexes

Well-Known Member
Licensed User
I didn't even know about text to speech
There was another person recently who was using the text-to-speech module to output to files; not quite sure why. But if you need to know 100% that the speech is there when you need it, and not possibly relying upon internet connectivity, then that could be something to look at.

Android Question: SynthesizeToFile and text length

What voice/accents are used in this? Can those be changed?
I think it defaults to your phone's locale setting, eg: Australia = English. But the voice I hear has an Australian accent, so perhaps it is more fine-grained than just the language.

It can be changed to other languages; I quite like that it can speak English text with a French accent.

upload_2019-3-30_21-37-56.png


I thought that I might get s friendly Samoan voice to record the word bites I needed.
That sounds more like you'll have to revert back to your sound-bite-recording method that you spoke of originally. Which is what they did with the TomTom GPS voices, and had the advantage that you could change the words too, eg, the royal voice saying: "in 100 metres, one will reach one's destination".

Minor digression: There was a speech synthesizer for the Apple II called SAM (Software Automatic Mouth) which would let you write in phonemes and tweak each one individually - you could get some surprisingly good-sounding accents out of that one.
 

Kevin Hartin

Member
Licensed User
Thanks all, I have used Text to Speech, with a nice female Aussie accent. I tried tricking it into pronouncing Samoan place names, but could only get about 40% to work properly.
 
Top