def bus_event(self,bus, message): peak = message.structure["peak"][0] print peak if peak>-51 and peak < 1: self.emit( QtCore.SIGNAL( "send( PyQt_PyObject)"), peak) if peak < self.ui.horizontalSlider_2.value(): #print peak self.player.set_state(gst.STATE_NULL) #self.ui.label_5.setText("Terminado") #self.ui.label_5.setText("Conectado") #self.ui.label_4.setText("") query = QSqlQuery(db) conv=gnonlin() try: a = ogg.vorbis.VorbisFile(f) t=0 except: t=1 os.remove(f) if t == 0: a.__methods__ ['bitrate', 'bitrate_instant', 'comment', 'info', 'pcm_seek', 'pcm_seek_page', 'pcm_tell', 'pcm_total', 'raw_seek', 'raw_tell','raw_total', 'read', 'seekable', 'serialnumber', 'streams','time_seek', 'time_seek_page', 'time_tell', 'time_total'] if a.time_total(0) >= 1: conv.convertir(f,0,0) if a.time_total(0) >= 2: tiempo=int(math.floor(a.time_total(0))-2) else: tiempo=int(math.floor(a.time_total(0))-1) conv.convertir(f,tiempo,1) dtmf = DTMFdetector() dtmf0= dtmf.getDTMFfromWAV("salida_0.wav") if len(dtmf0) == 0: dtmf0= dtmf.getDTMFfromWAV("salida_1.wav") if len(dtmf0) > 0: pass else: dtmf0="Desconocido" p = base + dtmf0 + '_' + fecha + '_' + hora +'.ogg' os.rename(f,p) query.exec_("INSERT INTO radios_grabacion (codigo, hora, fecha, audio,radio) values('%s', '%s', '%s', '%s', '%s')" % (dtmf0,hora,fecha,p,radio)) self.emit( QtCore.SIGNAL( "send2( PyQt_PyObject)"), dtmf0) #self.ui.label_4.setText(dtmf0) else: os.remove(f) print("Borrado" + f) self.abrir_inp() self.ctimer.start() return True
def __init__(self, pFrequency=8000, pDebugFlag=False, pSampleSize=16, pChannels=1, pEncoding="PCM"): self._frequency = pFrequency self._debugFlag = pDebugFlag # unused & unimplemented settings # but defined here in case # implemented in the future self._sampleSize = pSampleSize self._channels = pChannels self._encoding = pEncoding # init the DTMF detector with given settings self._detector = DTMFdetector(self._frequency, self._debugFlag)
class DetectDtmfFromFileLibrary: """Test library for detecting DTMF digits from a wave audio file. Default supported & tested audio file formats are 16-bit, mono, 8kHz, PCM encoding (default format) 16-bit, mono, 16kHz, PCM encoding (doesn't work well) For other sample sizes, frequencies, and encoding formats, you will have to modify the library source code to support them. Library currently has parameters to set these other formats but ignores them as functionality not implemented. *NOTE:* If you try and supply a wave audio file w/ unsupported audio file format, library will likely return an error or unreliable results. Best suggestion for using audio files in other formats is to use converter to get them into supported format for DTMF detection. For command line/automation processing, suggest Sox - http://sox.sourceforge.net. Or use the SoxAudioConversionLibrary that's part of the telcotools4robotframework package. *Reference:* frequency (Hz) = 8000, 16000, 11025, 22050, 44100, etc. sample size, in bits = 8, 16 channels = 1 for mono, 2 for stereo encoding = PCM, ADPCM, mu-Law, a-Law, etc. This test library is built upon public domain DTMF detection library from http://johnetherton.com/projects/pys60-dtmf-detector """ __version__ = '1.0' ROBOT_LIBRARY_SCOPE = 'GLOBAL' def __init__(self, pFrequency=8000, pDebugFlag=False, pSampleSize=16, pChannels=1, pEncoding="PCM"): self._frequency = pFrequency self._debugFlag = pDebugFlag # unused & unimplemented settings # but defined here in case # implemented in the future self._sampleSize = pSampleSize self._channels = pChannels self._encoding = pEncoding # init the DTMF detector with given settings self._detector = DTMFdetector(self._frequency, self._debugFlag) def get_dtmf_from(self, wavFile): """Extract and return a string of DTMF digits from given wave audio file. Given wave file must be full absolute path, or otherwise relative path will be used. Recommend use of absolute paths. """ try: data = self._detector.getDTMFfromWAV(wavfile) print data return data except IOError, err: print "Failed to get DTMF from %s. %s" % (path, err)
def __init__(self, pFrequency=8000, pDebugFlag=False, pSampleSize=16, pChannels=1, pEncoding="PCM"): self._frequency = pFrequency self._debugFlag = pDebugFlag # unused & unimplemented settings # but defined here in case # implemented in the future self._sampleSize = pSampleSize self._channels = pChannels self._encoding = pEncoding # init the DTMF detector with given settings self._detector = DTMFdetector(self._frequency,self._debugFlag)
class DetectDtmfFromFileLibrary: """Test library for detecting DTMF digits from a wave audio file. Default supported & tested audio file formats are 16-bit, mono, 8kHz, PCM encoding (default format) 16-bit, mono, 16kHz, PCM encoding (doesn't work well) For other sample sizes, frequencies, and encoding formats, you will have to modify the library source code to support them. Library currently has parameters to set these other formats but ignores them as functionality not implemented. *NOTE:* If you try and supply a wave audio file w/ unsupported audio file format, library will likely return an error or unreliable results. Best suggestion for using audio files in other formats is to use converter to get them into supported format for DTMF detection. For command line/automation processing, suggest Sox - http://sox.sourceforge.net. Or use the SoxAudioConversionLibrary that's part of the telcotools4robotframework package. *Reference:* frequency (Hz) = 8000, 16000, 11025, 22050, 44100, etc. sample size, in bits = 8, 16 channels = 1 for mono, 2 for stereo encoding = PCM, ADPCM, mu-Law, a-Law, etc. This test library is built upon public domain DTMF detection library from http://johnetherton.com/projects/pys60-dtmf-detector """ __version__ = '1.0' ROBOT_LIBRARY_SCOPE = 'GLOBAL' def __init__(self, pFrequency=8000, pDebugFlag=False, pSampleSize=16, pChannels=1, pEncoding="PCM"): self._frequency = pFrequency self._debugFlag = pDebugFlag # unused & unimplemented settings # but defined here in case # implemented in the future self._sampleSize = pSampleSize self._channels = pChannels self._encoding = pEncoding # init the DTMF detector with given settings self._detector = DTMFdetector(self._frequency,self._debugFlag) def get_dtmf_from(self, wavFile): """Extract and return a string of DTMF digits from given wave audio file. Given wave file must be full absolute path, or otherwise relative path will be used. Recommend use of absolute paths. """ try: data = self._detector.getDTMFfromWAV(wavfile) print data return data except IOError, err: print "Failed to get DTMF from %s. %s" % (path, err)
def rec_hash(): if request.method == 'POST': base= request.form['sound'] base=base.replace("data:audio/wav;base64,","") wavefile = base64.b64decode(base) filename = 's.wav' # I assume you have a way of picking unique filenames with open(filename, 'wb') as f: f.write(wavefile) cmd = "sox s.wav -C 256 -r 16000 ns2.wav" print os.system(cmd) dtmf = DTMFdetector() data = dtmf.getDTMFfromWAV("ns2.wav") new_str="%" for i in range(len(data)): new_str=new_str+data[i]+"%" try: msg_val = session.query(Msgkey).filter(Msgkey.hash_key.like(new_str)).one() # return render_template('rec_hash.html',msg = base) return msg_val.name except: return data
def Main(): Wav_File = str(os.path.abspath(os.path.dirname(sys.argv[0])) + "\\temp.wav") Rec = Recorder() Dtmf = DTMFdetector() DtmfChars = "" re1 = "(CB)" re2 = "(\\d\d\d\d\d\d\d\d\d\d)" rg = re.compile(re1 + re2, re.IGNORECASE | re.DOTALL) print "Initialized and Ready" while 1: Rec.record(1, Wav_File) Data = Dtmf.getDTMFfromWAV(Wav_File) DtmfChars += Data txt = DtmfChars m = rg.search(txt) if m: int1 = m.group(2) print "DTMF: " + DtmfChars print "Dialing: " + int1 cmd = "C:\Documents\ and\ Settings\Deacon\Desktop\SkHamPy\call.py +1" + str(int1) os.system(cmd) DtmfChars = ""
import pyaudio import wave import argparse #from pydub import AudioSegment import parse from DTMFdetector import DTMFdetector import sys freq = 8000 debugFlag = False dtmf = DTMFdetector(freq, debugFlag) FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 8000 CHUNK = 1 RECORD_SECONDS = 7 WAVE_OUTPUT_FILENAME = "output.wav" def listen(): """Listens for 3 seconds for audio""" audio = pyaudio.PyAudio() stream = audio.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK)
import sys # the mock-0.3.1 dir contains testcase.py, testutils.py & mock.py sys.path.append('C:\BSFT\Automation\Test\Trunk\Regression\UCOneChrome\Library') from DTMFdetector import DTMFdetector dtmf = DTMFdetector() data = dtmf.getDTMFfromWAV( "C:\\Users\\mganesan\\Desktop\\audio_debug.18632.source_input.8.wav") print data
import pyaudio import wave import os import sys import time from DTMFdetector import DTMFdetector if len(sys.argv) < 2: print("Records a wave file.\n\nUsage: %s filename.wav" % sys.argv[0]) sys.exit(-1) # instantiate PyAudio (1) p = pyaudio.PyAudio() d = DTMFdetector() d.reset() # define callback (2) def callback(in_data, frame_count, time_info, status): print("got framecount %d" % frame_count) #d.goertzel(in_data) return (in_data, pyaudio.paContinue) stream = p.open(format=pyaudio.paInt16, channels=1,rate=44100,input=True,frames_per_buffer=1024) stream.read(1024)# wait for stream to finish (5) # close PyAudio (7) p.terminate()
from DTMFdetector import DTMFdetector dtmf = DTMFdetector() data = dtmf.getDTMFfromWAV("ns2.wav") print data