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}

maybe just a typo?

loadtream -> loadStream

-finefin

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;

local play1 = audio.loadtream("1.MP3")

Has a typo in it. See?

Peach :)

Edit: Canupa beat me to it. You win this round ;)

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

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
-----------------------------
-- 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

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

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

uhm... no. not okay.

1
2
3
4
5
6
7
8
The following audio APIs should not be used:
media.newEventSound
media.playEventSound
media.playSound
media.pauseSound
media.stopSound
media.getSoundVolume
media.setSoundVolume
views:1788 update:2011/11/5 17:18:39
corona forums © 2003-2011