Problem with sound

hi dear
i want write one story when we will click on word(like:>Night) then sound should appears(like:>Night) but in my application when we are clicking on word then change the color of word but not appears sound

please help me—
local play1 = audio.loadtream(“1.MP3”)
audio.play(play1)
local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bg:setFillColor(255,255,255)
blackText={}
redText = {}
local soundLength = 0

– Data is obtained by loading the full audio track into Audacity (freeware
– sound editing program), selecting each word and creating a label. The word spoken
– is the name for the label. Then Export Labels to create a text file with the data.
– Times are in seconds, so multiply by 1000 to convert to milliseconds.
– Add newline=true where you want a CRLF (so the following line starts on a new line)
local voice = {
{start=0.359055, out=0.643383, name=“Twas”},
{start=0.643383, out=0.752740, name=“the”},
{start=0.752740, out=1.210217, name=“night”},
}

– Using the voice table, display the text by creating an object for each word
local function displayText(params)
local x,y,color,alpha = params.x, params.y, params.color, params.alpha
local xOffset = 0
local words={}
local fontSize = 32
local lineHeight = fontSize*1.33
local space = fontSize/5

for i = 1,#voice do
words[i] = display.newText(voice[i].name, x+xOffset, y, “Baskerville”, fontSize)
words[i]:setTextColor( color[1],color[2],color[3])
words[i].alpha = alpha
– convert to lower case and remove punctuation from name so we can use it
– to grab the correct audio file later
words[i].name = string.lower(string.gsub(voice[i].name, “[’.,]”, “”))
words[i].id = i
– calculate the duration of each word
words[i].dur = (voice[i].out - voice[i].start) * 1000
if params.addListner then
words[i]:addEventListener( “tap”, speakWord )
end
xOffset = xOffset + words[i].width + space
if voice[i].newline then y = y + lineHeight; xOffset = 0 end
end
soundLength = voice[#voice].out*1000
return words
end

– Add a button to start the talking
local function displayButton(params)
local x,y,w,h,color = params.x, params.y, params.w, params.h, params.color
local rect = display.newRect(x, y, w, h)
rect:setFillColor(color[1],color[2],color[3])
return rect
end
– not currently being called
local function stopNBC()
audio.stop(“1.MP3”)
end

– The button was pressed, so start talking. Highlight each word as it’s spoken.
– trans1 is the delay in milliseconds for the fade to red as the word is spoken
– trans2 is the delay in milliseconds for the fade back to black after the word is spoken
– use a shorter trans1 value for snappier response. Longer trans2 to make the fade
– back to black more fluid.
local function saySentence(event)
local delay1, delay2, trans1, trans2 = 0,0,20,40
audio.play(“1.MP3”)

– switch to red button so it’s not touchable
transition.dissolve(blackButton,redButton,trans1,0)
transition.dissolve(redButton,blackButton,trans1,soundLength+trans2)

for i = 1,#voice do
– start transition early so it’s full red by the time the word is spoken
delay1 = voice[i].start*1000 - trans1
if delay1 <0 then delay1 = 0 end
– add extra time at the end so we never finish before the fade is complete
delay2 = voice[i].out*1000 + trans2
transition.dissolve(blackText[i],redText[i],trans1,delay1)
transition.dissolve(redText[i],blackText[i],trans2,delay2)
end
end

– A word was touched, so say it now. Disabled during speech.
function speakWord( event )
local word = event.target
local id, name, dur = word.id, word.name, word.dur
local trans = 100
– was the sentence button pushed or this word already active? If so, return now.
if blackButton.alpha == 0 or word.alpha ~= 1 then return end
– make sure the duration is at least longer than 2 transition times
dur = dur + 2*trans
audio.play(“snippets/”…name…".MP3")-- i think problem is here
transition.dissolve(word,redText[id],trans,0)
transition.dissolve(redText[id],word,trans,dur)
return true
end

– initialize
redButton = displayButton{x=40,y=210,w=40,h=40,color={255,0,0}}
blackButton = displayButton{x=40,y=210,w=40,h=40,color={60,60,60}}
blackButton:addEventListener( “tap”, saySentence )

blackText = displayText{x=100,y=200,color={60,60,60},alpha=1,addListner=true}
redText = displayText{x=100,y=200,color={255,0,0},alpha=0}

[import]uid: 87661 topic_id: 17258 reply_id: 317258[/import]

maybe just a typo?

loadtream -> loadStream

-finefin [import]uid: 70635 topic_id: 17258 reply_id: 65205[/import]

Hey there,

Firstly I’m moving this out of “feature requests” because it is not a feature request.

Secondly, please post your code in < lua > tags so it isn’t a huge headache to try and read it - you’ll get more help this way.

With your code, this line;

[lua]local play1 = audio.loadtream(“1.MP3”)[/lua]

Has a typo in it. See?

Peach :slight_smile:

Edit: Canupa beat me to it. You win this round :wink: [import]uid: 52491 topic_id: 17258 reply_id: 65208[/import]

local play1 = audio.loadtream(“1.MP3”), unfortunate i wrote this , but i am using “local play1 = audio.loadStream(“1.MP3”)” audio is coming

but i want sound word by word (like:>“Unce”, “Upon”,“a”,“Time”)this thinks are not working…please help me [import]uid: 87661 topic_id: 17258 reply_id: 65218[/import]

Ah! I see the problem.
You are trying to audio.play a sound file directly, but you need a handler! I’m still working on my game helper module right now, but here’s the snippet dealing with sounds:

-----------------------------  
-- Setup Sound Table --  
----------------------------  
-- example: fin.initSounds ( sound table )  
-- return: nothing  
--  
--[[ usage:  
  
-- 1. create a sound table that holds all your sounds:  
  
 gameSounds= {  
 ["laserSound"] = audio.loadSound( "laser.wav" ),  
 ["secLaserSound"] = audio.loadSound( "secShoot.wav" ),  
 ["explosionSound"] = audio.loadSound( "explo.wav" )   
 }  
  
-- 2. call   
 fin.initSounds (gameSounds)  
  
-- 3. to play a sound, call   
 fin.playSnd ("laserSound")  
  
----------------------------- ]]--  
 -- Main helper table --  
 local fin = {}  
 -- sound table --  
 local gameSounds = {}  
  
 fin.initSounds = function ( theTable )  
 gameSounds = theTable   
 end  
  
-----------------------------  
-- Play Sound --  
----------------------------  
-- example: fin.playSnd ( sound name string)  
-- return: nothing  
-----------------   
 fin.playSnd = function ( soundName )  
 local theSound = soundName  
 local sndChanFree = audio.findFreeChannel()  
 audio.play( gameSounds[soundName], { channel = sndChanFree } )  
 end  

hope that helps

-finefin [import]uid: 70635 topic_id: 17258 reply_id: 65226[/import]

it is not working as well as not showing any error…i want ask one think
i have created one file all word voice there = “wordvoice” then i am using this code–

function speakWord( event )
local word = event.target
local id, name, dur = word.id, word.name, word.dur
local trans = 200
– was the sentence button pushed or this word already active? If so, return now.
if blackButton.alpha == 0 or word.alpha ~= 1 then return end
– make sure the duration is at least longer than 2 transition times
local dur = dur + 2*trans
it is ok ::> media.playEventSound(“wordvoice/”…name…".mp3")
transition.dissolve(word,redText[id],trans,0)
transition.dissolve(redText[id],word,trans,dur)
return true
end

[import]uid: 87661 topic_id: 17258 reply_id: 65237[/import]

>> it is ok ::> media.playEventSound(“wordvoice/”…name…".mp3")

uhm… no. not okay.

The following audio APIs should not be used:  
media.newEventSound  
media.playEventSound  
media.playSound  
media.pauseSound  
media.stopSound  
media.getSoundVolume  
media.setSoundVolume  

http://developer.anscamobile.com/content/multimedia
Use audio API. and as I told you before: you need a handler!

soundPath = "wordvoice/"..name..".mp3" -- this is the path  
mySound = audio.loadSound( soundPath ) -- this is the handler  
audio.play( mySound ) -- and this line plays the sound  

get it now? [import]uid: 70635 topic_id: 17258 reply_id: 65249[/import]