コード例 #1
0
    class InbandDtmfDetector:
        def __init__(self, leg):
            from shtoom.doug.dtmf import DtmfDetector
            self.leg = leg
            self.prev = None
            self.D = DtmfDetector()
            self.digit = ''

        def __call__(self, samp):
            if self.prev is None:
                self.prev = samp
                return
            nd = self.D.detect(self.prev + samp)
            if nd != self.digit:
                if self.digit == '':
                    self.digit = nd
                    self.leg.leg_startDTMFevent(nd)
                elif nd == '':
                    old, self.digit = self.digit, nd
                    self.leg.leg_stopDTMFevent(old)
                else:
                    old, self.digit = nd, self.digit
                    self.leg.leg_stopDTMFevent(old)
                    self.leg.leg_startDTMFevent(self.digit)
            self.prev = samp
コード例 #2
0
 def test_dtmfdetection_canned(self):
     from shtoom.doug.dtmf import DtmfDetector
     fp = open(getDTMFAudioFile(),'rb')
     dtmf = DtmfDetector()
     seen = []
     cur = None
     while True:
         data = fp.read(640)
         if len(data) != 640:
             break
         digit = dtmf.detect(data)
         if digit != cur:
             seen.append(digit)
             cur = digit
     self.assertEquals(seen, ['', '3', '', '1', '', '4', '', '1', '', '#'])
コード例 #3
0
ファイル: leg.py プロジェクト: braams/shtoom
 class InbandDtmfDetector:
     def __init__(self, leg):
         from shtoom.doug.dtmf import DtmfDetector
         self.leg = leg
         self.prev = None
         self.D = DtmfDetector()
         self.digit = ''
     def __call__(self, samp):
         if self.prev is None:
             self.prev = samp
             return
         nd = self.D.detect(self.prev+samp)
         if nd != self.digit:
             if self.digit == '':
                 self.digit = nd
                 self.leg.leg_startDTMFevent(nd)
             elif nd == '':
                 old, self.digit = self.digit, nd
                 self.leg.leg_stopDTMFevent(old)
             else:
                 old, self.digit = nd, self.digit
                 self.leg.leg_stopDTMFevent(old)
                 self.leg.leg_startDTMFevent(self.digit)
         self.prev = samp