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}