定制的频率和持续时间发出蜂鸣声 [英] Beep with custom frequency and duration

查看:931
本文介绍了定制的频率和持续时间发出蜂鸣声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Mac OS X播放信号音,并指定时长和频率。在Windows上可以使用的 Beep函数 Console.Beep 在.net) 。有什么等值的Mac吗?我知道NSBeep的,但它不带任何参数。

I want to play Beep sound in my Mac Os X and specify duration and frequency. On Windows it can be done by using Beep function (Console.Beep in .Net). Is there anything equivalent in Mac? I am aware of NSBeep but it does not take any parameters.

推荐答案

在Mac上,系统提示音是一个采样(prerecorded)声音,用户选择。它往往听起来完全不像蜂鸣声 - 它可能是一个按喇叭,thunk的,呜呜,或其他的声音,不能像固定形状,频率和幅度的简单恒波形。它甚至可以是用户的语音的记录,或者从一个电视节目或电影或游戏或歌曲剪辑

On the Mac, the system alert sound is a sampled (prerecorded) sound that the user chooses. It often sounds nothing like a beep—it may be a honk, thunk, blare, or other sound that can't be as a simple constant waveform of fixed shape, frequency, and amplitude. It can even be a recording of the user's voice, or a clip from a TV show or movie or game or song.

它也不会需要仅一个声音。其中的一个辅助功能选项是当警报声起闪屏;这种时会自动播放警报声音(或自定义提示音),但不是当你通过正常声音播放API,如NSSound播放声音。

It also does not need to be only a sound. One of the accessibility options is to flash the screen when an alert sound plays; this happens automatically when you play the alert sound (or a custom alert sound), but not when you play a sound through regular sound-playing APIs such as NSSound.

这样,有发挥特定和恒定的形状,频率和振幅的一个自定义的蜂鸣没有简单的方法。任何这样的蜂鸣将从用户选择的警报声音不同,并在所有可能无法察觉到用户

As such, there's no simple way to play a custom beep of a specified and constant shape, frequency, and amplitude. Any such beep would differ from the user's selected alert sound and may not be perceptible to the user at all.

要播放警报声在Mac上,使用 NSBeep 或稍微复杂 AudioServicesPlayAlertSound 。后者允许您使用自定义的声音,但即使是这些必须是prerecorded,或通过使用更多的Core Audio code比是值得书写的提前应用至少产生。

To play the alert sound on the Mac, use NSBeep or the slightly more complicated AudioServicesPlayAlertSound. The latter allows you to use custom sounds, but even these must be prerecorded, or at least generated by your app in advance using more Core Audio code than is worth writing.

我推荐使用 NSBeep 。这是code的一行尊重用户的选择。

I recommend using NSBeep. It's one line of code to respect the user's choices.

这篇关于定制的频率和持续时间发出蜂鸣声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆