sequential sound play

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ncmac
Posts: 31
Joined: Thu Apr 27, 2006 10:29 pm

sequential sound play

Post by ncmac » Wed May 30, 2012 7:28 pm

I have spent hours on this and can't get it right, so I appreciate any and all help! I am working on an iPad app that has a sentence building section. The use clicks on a button to add a word (+ a space if it isn't the first word) to field "MWField". This script is used to have the field play back each word as a sentence. It works fine in the simulator, but on the iPad the first word is not played back. Any thoughts?

on speakAll
put the number of words in card field "MWField" of this card into numWords
if numWords > 0 then
repeat with n = 1 to numWords
if there is a word n of card field "MWField" then put word n of card field "MWField" & ".mp3" into var1
play (specialFolderPath("engine") & "/audio/" & var1)
wait until the sound is done
end repeat
end if
end speakAll

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: sequential sound play

Post by jmburnod » Wed May 30, 2012 9:41 pm

Hi ncmac

try this

Code: Select all

on speakAll
   put the number of words in field "MWField" of this card into numWords
   if numWords > 0 then 
      repeat with n = 1 to numWords
         if there is a word n of field "MWField" then put word n of  field "MWField" & ".mp3" into var0
         put urlencode(var0) into var1
         play (specialFolderPath("engine") & "/audio/" & var1) 
         wait until the sound is done
      end repeat
   end if
end speakAll
Best regards

Jean-Marc
https://alternatic.ch

ncmac
Posts: 31
Joined: Thu Apr 27, 2006 10:29 pm

Re: sequential sound play

Post by ncmac » Wed May 30, 2012 10:13 pm

Thanks Jean-Marc, but it still isn't working. If "She is eating an apple" is in the field, the only words played back are "is eating and apple". I have tried repeat for and using word 1 to -1 and the result is always the same; The first word is not played back. I know the sound file is OK because it plays in any other position.

ncmac
Posts: 31
Joined: Thu Apr 27, 2006 10:29 pm

Re: sequential sound play

Post by ncmac » Wed May 30, 2012 10:18 pm

I think I have solved it. I have the first word getting capitalized, and the filename is case sensitive!

ncmac
Posts: 31
Joined: Thu Apr 27, 2006 10:29 pm

Re: sequential sound play

Post by ncmac » Wed May 30, 2012 10:25 pm

So now the question is if there is a way to check for an uppercase letter, behind the scenes so the user still see's the "Correct" sentence format. I checked the dictionary and didn't see anything for Uppercase, capitol or even the textStyle.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: sequential sound play

Post by bn » Wed May 30, 2012 11:54 pm

Hi ncmac,

check "toLower" in the dictionary. You could take your words and convert them to all lowercase on the fly when passing the word to the filename.

Kind regards
Bernd

ncmac
Posts: 31
Joined: Thu Apr 27, 2006 10:29 pm

Re: sequential sound play

Post by ncmac » Thu May 31, 2012 12:30 am

Thanks!

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: sequential sound play

Post by Klaus » Thu May 31, 2012 9:22 am

Hi ncmac,

a short hint:

Code: Select all

on speakAll
   put the number of words in card field "MWField" of this card into numWords
   if numWords > 0 then 
      repeat with n = 1 to numWords
         if there is a word n of card field "MWField" then put word n of card field "MWField" & ".mp3" into var1
         play (specialFolderPath("engine") & "/audio/" & var1) 
         wait until the sound is done
      end repeat
   end if
end speakAll
If nobody "stole" a word from the field after line 2 of your script, then the following IF THEN clause does not make any sense! :D
...
if there is a word n of card field "MWField" then put word n of card field "MWField" & ".mp3" into var1
...
Of course there is ALWAYS a word N of that field!

Code: Select all

on speakAll
   put the number of words in card field "MWField" of this card into numWords
   if numWords > 0 then 
      repeat with n = 1 to numWords
         put word n of card field "MWField" & ".mp3" into var1
         play (specialFolderPath("engine") & "/audio/" & var1) 
         wait until the sound is done
      end repeat
   end if
end speakAll
Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: sequential sound play

Post by jacque » Thu May 31, 2012 5:44 pm

For the truly compulsive, the check for "numWords > 0" isn't required either. If numwords is zero, the repeat won't run at all. And the super-ultra-compulsive would remove all the extra lines and condense it to this:

Code: Select all

on speakAll
    repeat with n = 1 to the number of words in card field "MWField" of this card
       play (specialFolderPath("engine") & "/audio/" & word n of card field "MWField")
       wait until the sound is done
    end repeat
end speakAll
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

ncmac
Posts: 31
Joined: Thu Apr 27, 2006 10:29 pm

Re: sequential sound play

Post by ncmac » Fri Jun 01, 2012 3:46 am

I understand what you and Klaus are saying. Somehow it is reassuring to me to write in an exit to a script. So you are right on the compulsive part!

Post Reply