Module tones
[hide private]
[frames] | no frames]

Source Code for Module tones

 1  #tones.py 
 2  #A part of NonVisual Desktop Access (NVDA) 
 3  #Copyright (C) 2006-2009 NVDA Contributors <http://www.nvda-project.org/> 
 4  #This file is covered by the GNU General Public License. 
 5  #See the file COPYING for more details. 
 6   
 7  """Utilities to generate and play tones""" 
 8   
 9  import nvwave 
10  import config 
11  import globalVars 
12  from logHandler import log 
13  from ctypes import create_string_buffer, byref 
14   
15  SAMPLE_RATE = 44100 
16   
17  try: 
18          player = nvwave.WavePlayer(channels=2, samplesPerSec=int(SAMPLE_RATE), bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"]) 
19  except: 
20          log.warning("Failed to initialize audio for tones") 
21          player = None 
22   
23 -def beep(hz,length,left=50,right=50):
24 """Plays a tone at the given hz, length, and stereo balance. 25 @param hz: pitch in hz of the tone 26 @type hz: float 27 @param length: length of the tone in ms 28 @type length: integer 29 @param left: volume of the left channel (0 to 100) 30 @type left: integer 31 @param right: volume of the right channel (0 to 100) 32 @type right: float 33 """ 34 log.io("Beep at pitch %s, for %s ms, left volume %s, right volume %s"%(hz,length,left,right)) 35 if not player: 36 return 37 from NVDAHelper import generateBeep 38 bufSize=generateBeep(None,hz,length,left,right) 39 buf=create_string_buffer(bufSize) 40 generateBeep(buf,hz,length,left,right) 41 player.stop() 42 player.feed(buf.raw)
43