How can make sound only play once in pygame? - python-3.x

When the user trigger a condition,I need to play a sound once.It is in major cycle of while,so it always play many times.Please solve the little problem.Thanks.

Include at the start of your loop the code playsound = True. Then in your loop put the following:
if playsound:
# Play the sound
playsound = False
Put your current command for playing in place of # Play the sound, it probably looks something like sound.play().

Related

Why is my sprite's costume not changing in scratch when the statement of a function becomes true?

Why is my sprite's costume not changing in scratch when the statement of a function becomes true?
I have the following code:
For some reason it doesn't change the costume.
Change the block "play sound ...WAV FINAL until done" to: start sound ...WAV FINAL" What's happening is that the program waits until the sound is done playing to then check to change the costume

Vuforia video playback with fixed dimension

I am using vuforia video playback demo with cloud recognition.
I have combined both projects and it is working properly. But currently video dimension is according to detected object. But i need fixed width and height when video plays.
Can anyone help me ?
Thanks in advance.
Well apparently Vuforia fixes the width and height at the start of the game no matter what the size of the object is. I could not find when exactly this operation is conducted but it is done at beginning of your game. When you change the size of the ImageTarget in runtime it is not fixed anymore. Add these lines to your OnTrackingFound function of DefaultTrackableEventHandler.cs
if (this.name == "WhateverTheNameOfYourRelatedImageTarget"&& !isScaled)
{
//Increase the size however you want i just added 1 to each dimension
this.transform.localScale += Vector3.one;
// make isScaled true not to scale every time it is found initially it shoud be false
isScaled = true;
}
Good luck!
What i usually do is , instead of Videoplayback , i play the video on canvas object and hook this object to Defaulttrackableeventhandler script. So when target is found, gameobject.setactive(true) and gameobject.setactive(false) when target is lost. By this method the size of the gameobject is fixed and it stays in a fixed location .
I just made an example you can get here (have to import it to any project and open the scene Assets/VideoExample/Examples). You can see there a bit clearer what the ScreenSpace - Overlay does ... it might be better to just switch to ScreenSpace - Camera in general

Loop a Video on Echo Show

I'm building a skill for Echo Show and I've been trying to loop a video (mp4) file. I use the below code to play the video:
if (this.event.context.System.device.supportedInterfaces.VideoApp) {
this.response.playVideo(LINK);
} else {
this.response.speak("The video cannot be played on your device. " +
"To watch this video, try launching the skill from your echo show device.");
}
Unfortunately, regardless of which looping function I use, I either run into a general Amazon error or it simply plays the video once.
I've seen another post that kinda showed how to loop an audio file, but I haven't been able to apply similar logic to video.
Thanks in advance!
The problem is looping is not yet supported for VideoApp directive. You can use Video apl component to loop a video. https://developer.amazon.com/de/docs/alexa-presentation-language/apl-video.html

How to select random .wav/.mp3 file from folder with Garry's mod?

I've recently started Coding a program that will replace sound effects from a default directory, in the Source-Engine Game, Garry's Mod.
This is the current code:
function GM:PlayerFootstep( ply, pos, foot, sound, volume, rf )
ply:EmitSound("gear1")
return true
end
I want to emit multiple .wav Sound effects, without them overlapping, and being selected at random.
I have not found any Source helpful enough on the Internet to assist, so i resorted to Stack Overflow.
I would appreciate assistance with the topic.
You'll want to look at the file.Find function for this.
I'd recommend having a custom folder such as sound/customsteps/ where you can put all your custom sounds. I would also recommend using the .wav format for the sound files, but some others do work (.mp3 and .ogg if I recall correctly).
In your code, simply call local snds=file.Find( "sound/customsteps/*", "GAME" ) which gives you a table, then you can simply choose a random one from the list using local snd=snds[math.random(1,#snds)] and play it as you do in your above code - ply:EmitSound(snd).
Make sure you create the table of sounds outside of the GM:PlayerFootstep function, so that it only runs once. I would also recommend precaching all the sounds. You can do this by looping through the table and calling util.PrecacheSound(path) on them, like so:
for k,v in pairs(snds) do
util.PrecacheSound(v)
end
So, with all that in mind - your final code should look something like this:
local snds=file.Find( "sound/customsteps/*", "GAME" )
for k,v in pairs(snds) do
util.PrecacheSound(v)
end
function GM:PlayerFootstep( ply, pos, foot, sound, volume, rf )
ply:EmitSound(snds[math.random(1,#snds)])
return true
end
Source: personal experience

How would I play a .wav file with a Mathematica program?

I would like to know an easy way to implement a function playWav[filename_String] that plays a .wav file (as a side effect).
playSound[filename_String] := EmitSound # Import[filename, "WAV"]
Changing the "wav" to "Sound" allows it to play without GUI
playSound[filename_String] := EmitSound # Import[filename, "Sound"]

Resources