Ruby声音
转 Adding Sound to Your Ruby Apps
Have you ever thought about including sounds in your Ruby application? Used sparingly, sound may enhance your applications by adding audio cues or a custom touch. You could, for example, play a beep or chime that announces the completion of a lengthy process. Perhaps a humorous sound to accompany an error message .
The win32-sound library makes using sounds really simple.
If you installed Ruby with the One-Click Ruby Installer, then you probably already have the win32-sound library installed, along with other win32 utilities. Otherwise, you can install it in seconds via gem. Open up a console window and enter..
gem install win32-sound
To use the win32-sound library, add these require and include statements to the top of your script...
require 'win32/sound'
include Win32
Then, to play a sound file on the PC, call the Sound.play method, passing it the name of the file...
Sound.play('chimes.wav')
Sound.play('c:\sounds\hal9000.wav')
In the example above, you don't have to include the path to the file 'chimes.wav', because 'chimes.wav' is usually installed in the Windows folder. But in most cases, you'll want to include the full path to the sound file.
To generate a simple beep, call the Sound.beep method, passing it the tone frequency (in Hertz, between 37 and 32767) and the duration in milliseconds. For example, to play a low tone for half a second...
Sound.beep(100, 500)
...or to play an annoyingly high-pitched tone for 3 full seconds...
Sound.beep(5000, 3000)
The complete docs for this library can be found here.
Distributing your sound files with your application is also simple. You can embed your sound files in an executable created with RubyScript2Exe, or include them in an install package produced with Inno Setup.
Be careful not to overdo it, though, if your program is to be used by others besides yourself. It's a fine line between clever and annoying.
注:
win-32声音库文件夹位置为
C:\WINDOWS\Media
Sound.pl
相关文档:
从命令行启动Ruby解释器时,你不仅可以提供程序文件的名字,而且可以提供一个或多个命令行开关。你选择的开关指示解释器以一种特定的方式运转,并且/或者执行特定的操作。
Ruby命令行开关有20多个,其中有些很少使用,有些则每天被很多Ruby程序员使用。在这里我们将再看几个最常用的。(你已经看到过其中的两个,-c和&ndas ......
为了选择一个合适的脚本语言学习,今天查了不少有关Perl,Python,Ruby,Javascript的东西,可是发现各大阵营的人都在吹捧自己喜欢的语言,不过最没有争议的应该是Javascript现阶段还不适合用来做独立开发,它的天下还是在web应用上。 我主要是想做数据挖掘算法的研究,应该会处理大量的文本。提到文本处理,相信大部分人 ......
http://www.gayathri-frenzy.com/technology/ruby-on-rails
I kept thinking for a while on what do I have next in the store
Here we go “Ruby on Rails”
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby Programming language.Ruby is a ......
Beginning Ruby from Novice To Perfessional
Head First Rails
Agile Web Development with Rails 3rd Edition(new)
Agile Web Development with Rails 3rd Edition
Agile Web Development with Rails 3rd Editio ......
rubygems
Ruby on Rails 是一个可以使你开发,部署,维护 web 应用程序变得简单的框架。
Ruby的作者于1993年2月24日开始编写Ruby,直至1995年12月才正式公开发布于fj(新闻组)。之所以称为Ruby,是因为Perl的发音与6月的诞生石pearl(珍珠)相同,因此Ruby以7月的诞生石ruby(红宝石)命名。rails在英文中是栏杆的 ......