I have a problem with playing sounds.
The purpose is making a text to speech program that talks with my voice.
I recorded a lot of phonemes (.wav files with parts of speech) that need to play after each other in the right order.
each sound must play ONLY if the previous sound finished playing.
so if my program needs to say 'hello' then it does this:
**play("h.wav")
if "h.wav":isStopped() then:
play("e.wav")
if "e.wav":isStopped() then... etc ...**
For test purposes i want to play "a.wav" twice but the problem is that i only hear 'A' once...
if i play e.g. 'A' and then 'B', it works fine..
Any help would be mush appreciated!
This is the test code i currently have:
function love.load()
voice = {"a","b","e","f", ......}
for i in pairs(voice) do
voice[i] = love.audio.newSource("VOICE/" .. voice[i] .. ".wav", "static")
end
end
function love.keypressed(key)
if key == "a" then
voice[1]:play()
while voice[1]:isPlaying() do end
voice[1]:play()
while voice[1]:isPlaying() do end
end
end
Just a thought, what if you tried this:
if ( voice[ 1 ]:isPlaying() ) then
voice[ 1 ]:stop()
voice[ 1 ]:play()
end
I guess you could do that before playing any sound.
If you want to play the same sound twice simultaneously, you'll need to have multiple instances of the source.
SLAM, an audio manager library for Löve2D, handles this perfectly.
https://love2d.org/wiki/SLAM
Here's an example with SLAM that will play the same sound multiple times :
require("slam")
sounds = {
["testAudio"] = love.audio.newSource("testAudio.wav", "stream"),
}
for i = 1, 10 do
sounds["testAudio"]:play()
end
This way, any instance that's currently being played will not be stopped.
Related
I need to concatenate two wav audio files with 30 seconds of whute sound between them.
I want to use the NAudio library - or with any other way that work.
How to do it ?
( the different from any other question is that i need not only to make one audio file from two different audio files .. i also need to add silent between them )
Assuming your WAV files have the same sample rate and channel count, you can concatenate using FollowedBy and use SignalGenerator combined with Take to get the white noise.
var f1 = new AudioFileReader("ex1.wav");
var f2 = new SignalGenerator(f1.WaveFormat.SampleRate, f1.WaveFormat.Channels) { Type = SignalGeneratorType.White, Gain = 0.2f }.Take(TimeSpan.FromSeconds(5));
var f3 = new AudioFileReader("ex3.wav");
using (var wo = new WaveOutEvent())
{
wo.Init(f1.FollowedBy(f2).FollowedBy(f3));
wo.Play();
while (wo.PlaybackState == PlaybackState.Playing) Thread.Sleep(500);
}
I'm writing a MOD player, trying to playback a sample using Allegro5 raw stream capabilities, I can't figure out the exact init parameters for the stream to play the loaded sample data from the mod file.
This is what I have:
xf::ModLoader ml;
ml.loadFromFile("C:\\Users\\bubu\\Downloads\\agress.mod");
// getSampleLength() returns # of data words
int sample_length = ml.getSampleLength(1) * 2;
const int8_t* sample_data = ml.getSampleData(1);
ALLEGRO_MIXER* mixer = al_get_default_mixer();
ALLEGRO_AUDIO_STREAM* stream = al_create_audio_stream(1, sample_length, 8363, ALLEGRO_AUDIO_DEPTH_INT8, ALLEGRO_CHANNEL_CONF_1);
al_attach_audio_stream_to_mixer(stream, mixer);
al_set_audio_stream_gain(stream, 0.7f);
al_set_audio_stream_playmode(stream, ALLEGRO_PLAYMODE_ONCE);
al_set_audio_stream_playing(stream, true);
al_set_audio_stream_fragment(stream, (void*)sample_data);
al_drain_audio_stream(stream);
First of all, freq param is hardcoded for the test (8363Hz), but, playing back at the specified frequency I don't get what I expect, and al_drain_audio_stream() gets stuck forever playing garbage in a loop...
Any help would be appreciated.
At the very least, you need to be calling al_get_audio_stream_fragment before you call al_set_audio_stream_fragment. Typically you'd feed these streams in a while loop, while responding to the ALLEGRO_EVENT_AUDIO_STREAM_FRAGMENT event. See the ex_saw example in the Allegro's source for some sample code: https://github.com/liballeg/allegro5/blob/master/examples/ex_saw.c
I am currently making an extremely simple app where when an image is tapped, a sound plays and some text records the amount of clicks. However, I noticed some significant delay in the audio, where it would take half a second for the sound to play after the image is clicked. Does anyone have any ideas on why this might be the case?
local function btnTouch(event)
if event.phase == "began" then
media.playSound( "btnSnd.mp3" )
score = score + 1
btnText.text = score
return true
end
end
--code
imageBtn:addEventListener("touch", btnTouch)
The answer is probably that the sound needs to be loaded. Try and switch it to audio instead and preload it. Try and see if this gives you the desired result:
local buttonSendAudio = audio.loadSound( "btnSnd.mp3")
local function btnTouch(event)
if event.phase == "began" then
audio.play( buttonSendAudio )
score = score + 1
btnText.text = score
return true
end
end
--code
imageBtn:addEventListener("touch", btnTouch)
https://docs.coronalabs.com/daily/guide/media/audioSystem/index.html
Worth checking if sound has some silence stored in mp3.
Open it with any audio editor, see sound's waveform.
Lua novice asks:
How do I transition from this...
(a simple example to establish a how-to)...
visual = display.newImage( "redCircle.png", 50, 50 )
local music = audio.loadStream("sound1.mp3")
audio.play(music)
audio.stopWithDelay(60000/60)
to this, timed by the first sound file ending?
visual = display.newImage( "blueCircle.png", 50, 50 )
local music = audio.loadStream("sound2.mp3")
audio.play(music)
audio.stopWithDelay(60000/60)
Which api should I be experimenting with? I've looked at https://docs.coronalabs.com/api/index.html
What am I missing?
What you can do is create a function listener for the first audio file you can look more here: https://docs.coronalabs.com/api/library/audio/play.html Below is a sample code I can give you. Note that I did not use audio.stopWithDelay
--DECLARE LOCAL VARIABLES
local visual1
local visual2
local music1
local music2
--LOAD SOUNDS
music1 = audio.loadStream("sound1.mp3")
music2 = audio.loadStream("sound2.mp3")
local function soundIsFinished(event)
if (event.completed) then
--PLAY SECOND AUDIO AND HIDE/REMOVE VISUAL 1
visual1.isVisible = false
visual2.isVisible = true
audio.play(music2, {duration = 1000})
end
end
--DISPLAY VISUAL1 and play MUSIC1
visual1 = display.newImage("redCircle.png", 50,50)
--AUDIO WILL PLAY FOR 1 SECOND (60000/60) is 1 second
audio.play(music1, { duration=1000, onComplete=soundIsFinshed } )
-- HIDE VISUAL2 FIRST
visual2 = display.newImage("blueCircle.png", 50,50)
visual2.isVisible = false
Hope This helps.
I want to stop a sound when another starts playing .
if (event.object1.myName == "obst3") then
audio.play(colsound)
I want this one to stop if the following one starts .
if (event.object1.myName == "t") then
audio.play(explosion)
Also, I need to know how to launch the sound just once ( when my objects collide with a wall, a sound pop out I need this one to be heard just once even if the player touches again the wall.
Play every audio with reference id value :
if (event.object1.myName == "obst3") then
local isChannel1Playing = audio.isChannelPlaying( 2 )
if isChannel1Playing then
audio.stop( playLaserSound2 )
playLaserSound2 = nil
end
playLaserSound1 = audio.play(colsound, { channel=1 })
end
if (event.object1.myName == "t") then
local isChannel1Playing = audio.isChannelPlaying( 1 )
if isChannel1Playing then
audio.stop( playLaserSound1 )
playLaserSound1 = nil
end
playLaserSound2 = audio.play(explosion, { channel=2 })
end