I have an app which speaks to the user in a sexy female voice. Instead of a voice synthesizer, I have mp3 files of various words recorded by an actual sexy female, and use media player to output the audio as spoken sentences. I build up sentences from individual words as an array of the filenames and then use media player to play the array one word /file at a time.
This may be rather clunky, but it does work. (I'm open to improved alternative suggestions)
When it comes to speaking a number, I have mp3 files such as 1.mp3, 2.mp3, 13.mp3, 20.mp3, hundred.mp3, and so on which contain the spoken sounds for all the needed number words.
To enunciate, for example, the number 1024.6, this gets parsed into 6 separate audio files to play: "1.mp3", "thousand.mp3", "20.mp3", "4 .mp3", "point.mp3", "6,mp3" just as the number would normally be spoken as "one thousand twenty four point six"
Likewise, the number 913 is spoken as "nine hundred thirteen."
My code for doing this is as follows:
Now, I know that the expert coders here are either gasping in horror or laughing at my crude, inefficient method for translating numbers into audio filenames to generate speech like this. Hey, I'm dumb, okay? I have to break things down step by step to figure them out! That's why I am here, asking if someone can point me in a better, more elegant direction, using modulus in a loop or something, another way to parse numbers and concatenate the audio files to accomplish this same purpose?
As always, I am willing to DONATE to whoever has the most helpful answer to my question.
This may be rather clunky, but it does work. (I'm open to improved alternative suggestions)
When it comes to speaking a number, I have mp3 files such as 1.mp3, 2.mp3, 13.mp3, 20.mp3, hundred.mp3, and so on which contain the spoken sounds for all the needed number words.
To enunciate, for example, the number 1024.6, this gets parsed into 6 separate audio files to play: "1.mp3", "thousand.mp3", "20.mp3", "4 .mp3", "point.mp3", "6,mp3" just as the number would normally be spoken as "one thousand twenty four point six"
Likewise, the number 913 is spoken as "nine hundred thirteen."
My code for doing this is as follows:
B4X:
Public Sub Number(num As Double)
'Words() is a global array which will hold the sound filenames.
'WordCount is a global integer used as the array pointer and counter
Dim x, y As Double
WordCount = 0
If num >= 1000 Then
x=Floor(num/1000)
y = x*1000
Words(WordCount)=x
WordCount=WordCount+1
Words(WordCount)="thousand"
num = num -y
End If
If num >= 100 Then
x=Floor(num/100)
y = x*100
Words(WordCount)=x
WordCount=WordCount+1
Words(WordCount)="hundred"
num = num -y
End If
If num>19 Then 'This gets 20, 30, 40.... 90
x=Floor(num/10)
y = x*10
WordCount=WordCount+1
Words(WordCount)=y
num=num-y
End If
'the remainder is 1 through 19
x=Floor(num)
y=num-x
WordCount=WordCount+1
Words(WordCount)=x
num=num-x
If num > 0 Then
WordCount=WordCount+1
Words(WordCount)="point"
num=Round2(num,2)
num = Floor(num*100)
x=Floor(num/10)
WordCount=WordCount+1
Words(WordCount)=x
x=num-(x*10)
If x >0 Then
x=Floor(x)
WordCount=WordCount+1
Words(WordCount)=x
End If
End If
For i=0 To WordCount
Words(i)=Words(i) & ".mp3" 'adds the .mp3 extension to the sound filenames
Next
End Sub
As always, I am willing to DONATE to whoever has the most helpful answer to my question.