I'm trying to write a simple game in Ruby (ver 2.2.6) on Windows. I installed the Gosu gem to handle the audio, and I have a soundtrack file that I would like to play:
#soundtrack = Gosu::Song.new("theme.ogg")
I cannot use Sample, because I need to be able to pause.
def play_soundtrack
#soundtrack.play(looping = true)
end
def pause_soundtrack
print "Paused "
#soundtrack.pause
end
Running this only plays the first note of the theme, and then no sound will play. Gosu::Sample still works as it should, so I'm not sure what could be wrong with my use of Gosu::Song.
This is not possible with Gosu right now, Song#play does not work without a window. Because Gosu does not use a background thread to play audio, there is an internal Song::update() method that needs to be called periodically to keep the song playing. Gosu::Window#show does this once per tick. There is no way to directly call this method from Ruby. The only workaround is to show a tiny window while audio is playing.
I've opened a GitHub issue because this should either be documented or fixed.
Related
What I'm trying to do is:
1) use the Ruby TTS gem to read some text.
2) while the text is being read, I want to loop through an animation.
The way I'm calling the animation is this:
def animation
i = 1
while i < 3
print "\033[2J"
File.foreach("lib/narrabot/flair_folder/#{i}.txt") { |f| puts f }
sleep(0.03)
i += 1
end
end
What seems like a quirk (or feature) of the TTS gem is that if you hit a button on your keyboard while it's running... it will replay from where you interrupted... So, when I tried to run the loop assuming I could just "play" the text, TTS essentially stuttered and didn't run the animation until it ended and then it went back to the beginning.
I just required this gem... https://github.com/grosser/parallel but am not sure how to tackle my goal.
In case you're curious -- my project is here: https://github.com/AdamWeissman/narrabot
What I'm attempting to do is use TTS to read Aesop's Fables... and while a Fable is being read... an ascii animation of a fire will run in the background. Eventually, I hope to replace the image of the fire with an ascii face (sorta like a sock puppet... the intent is to get the mouth to move in sync -- relatively -- with the speech... but that's a long way off).
I am basically trying to script a GUI control panel that allows users to accelerate the train with a power lever (in the GUI) and a reverser (Forward, Neutral, Reverse)
I have made two scripts. One is a localscript, the other being a regular script. The regular script enables the GUI on a player's screen when the player sits in the seat. The localscript is what makes the GUI function.
I've scripted the entire thing but only the regular script seems to function, The localscript does not seem to function as it is scripted to. The GUI appears on the screen but when pressed it does nothing.
Here are the contents of the localscript
http://pastebin.com/raw/XnT2Bi2X
Here's are all the objects in the Workspace that is mentioned and relevant to the script:
https://s31.postimg.org/4hd2up2ij/Screen_Shot_2016_06_24_at_11_15_21_AM.png
What are the errors in the localscript that is not allowing the GUI to function as its scripted to?
(I apologize for the long script and thank you for your help in advanced)
Note: The codes are Lua (which are used on the ROBLOX Studio Platform)
First off, thanks for writing out a clear and concise question. Most of the questions under this tag are all over the place :).
I would verify that you LocalScript instance is being properly initialized inside of the Player instance that is sitting down. Looking over your LocalScript's code, I don't see any errors that would cause the GUI not to function (if the LocalScript is being initialized properly), which leads me to believe the LocalScript isn't even running. If you are loading the LocalScript into the player on spawn (so, putting it into the PlayerScripts folder), there's your problem. This would cause the GUI to not be set up properly, as it hasn't been inserted into the players PlayerGui instance yet, so the LocalScript won't be able to hook up the MouseButton1Click events or anything of that sort.
So, make sure that the LocalScript starts running once the player sits in the seat (use the regular Script that displays the GUI to also move a copy of the LocalScript into the player). This will (hopefully) initialize the LocalScript properly, and allow it to hook into the GUI.
If this doesn't work, check your output window for any blatant errors, and post em here.
Cheers!
-widoreu
I'm working on a very simple OSX application that will allow me to play either a song or a folder of songs.
I can choose a song and play it and everything is fine. I can choose a folder and create an array of songs and... play the last one.
var currentSong: NSURL?
var album: [NSURL] = []
var audioPlayer = AVAudioPlayer()
My playing function is
func playCurrent(){
do {
try audioPlayer = AVAudioPlayer(contentsOfURL: currentSong!)
} catch {
print("Ignoring errors for now")
}
audioPlayer.play()
}
This works fine whenever I set currentSong to a NSURL. I choose one song, it plays it.
My album function is as follows:
#IBAction func chooseAlbumAndPlay(sender: AnyObject) {
album = albumFromFile()
for song in album {
currentSong = song
playCurrent()
}
}
and here I have the problem. albumFromFile opens an NSOpenPanel, lets me choose a folder, and dumps paths to playable items into an array of NSURLs. This part works, I've verified it, so I really have an array with 12 or 20 or whatever correct, playable URLs. If I just run it as is, only the last song in any album gets played. If I set a breakpoint in the playCurrent() function, I can hear that it will actually play a tiny snippet - less than a note in most cases - of all songs but the last.
According to the documentation, play() returns a boolean - and it will happily report that it has finished playing every song in this loop.
My - human - opinion is that a song has only finished playing when I have heard all of it.
If I query the duration of the current AVAudioPlayer, they all report perfectly reasonable-sounding values.
I'm completely stumped here. PlayCurrent seems to completely fail to assert itself as a running function. The expected behaviour is that it will not exit until play() has finished playing; observed behaviour is that it will touch every song for the briefest time, go 'been there' and return to the enclosing loop.
How can I force AVAudioPlayer to play the whole of a file before exiting my playCurrent() function? And where would I have found that information? (The class documentation is unhelpful, the mentioned audio guides do not exist - right now, the Developer Library does not mention any basic audio guides for OSX.
The answer is, once you get around to it, very obvious indeed. Unfortunately, the documentation really is no help at all. I could, in theory, have found the solution by looking at the entry for AVAudioPlayer in the AVFoundationFramework reference, but I didn't. (I found it by wildly casting about and a chance mention).
There appear to be no working OSX examples; Apple's iOS example uses the MediaPlayer framework that is not available on OSX.
The solution is as follows:
An AVAudioPlayer plays a single sound.
If you want to play more than one sound, you need an AVQueuePlayer which can also play a single sound from a URL or a queue of AVPlayerItems (this class has an init(URL:) method).
If anyone has an idea why AVAudioPlayer behaves as it does, I'm still interested to hear it.
I have been working on a makeshift RPG, and the Regenerate function, is supposed to be called every 3 seconds, NO MATTER WHAT THE PLAYER's STATUS IS
For Example:
Shoes.app do
# Display on main screen
animate do
# Set para(s) to current values of health and other stats
end
every 3 do
RegenerateVitals
end
end
But at times, the user will click on buttons that will trigger functions and new windows (the base window will keep opened in the background at all times.)
Do the every function really runs behind the scenes every 3 seconds no matter what menu the player is on? Or do I need to do something else for that?
Thanks.
Yes, the specification is that every calls the block no matter what (as long as the main windows stays open). I looked up the implementation of shoes4 and that one definitely does it (using the SWT scheduler) but other implementations such as Shoes 3.1, 3.2 and green shoes should do the same.
I need to run a ruby client that wakes up every 10 minutes, takes a screen-shot (ss) of a users screen, crops part of the (ss) out and use's OCR to check for a matching word....its basically a program to make sure remote employees are actually working by checking that they have a specific application open & the case numbers shown change.
Not sure where to even start when it comes to taking a screen-shot and cropping it, has anyone done any kind of screen capture work using Ruby?
The app will run on OSX using Ruby 1.9
Thanks!
On OS X you can use the screencapture command in the terminal to capture the screen, so capturing the screen from Ruby shouldn't be more than
def screen_capture(path)
`screencapture #{path}`
end