Esempio n. 1
0
 def test_dtmfdetect_generated(self):
     from shtoom.doug import dtmf
     detect = dtmf.DtmfDetector()
     for k in dtmf.dtmf2freq.keys():
         s = dtmf.dtmfGenerator(k, 320)
         digit = detect.detect(s)
         self.assertEquals(k, digit)
Esempio n. 2
0
 def _test_with_codec(self, codec):
     from shtoom.doug import dtmf
     detect = dtmf.DtmfDetector()
     for k in dtmf.dtmf2freq.keys():
         s = dtmf.dtmfGenerator(k, 320)
         s1, s2 = s[:320], s[320:]
         s1res = []
         s2res = []
         for frame in codec.buffer_and_encode(s1):
             codec.decode(frame)
         for frame in codec.buffer_and_encode(s2):
             codec.decode(frame)
         for frame in codec.buffer_and_encode(s1):
             s1res.append(codec.decode(frame))
         for frame in codec.buffer_and_encode(s2):
             s2res.append(codec.decode(frame))
         self.assertTrue(len(s1res) == 1, s1res)
         self.assertTrue(len(s2res) == 1, s2res)
         s = s1res[0] + s2res[0]
         digit = detect.detect(s)
         self.assertEqual(k,
                          digit,
                          msg="k: %s, digit: %s, s=%s" % (
                              k,
                              digit,
                              ` s `,
                          ))
         silence = '\0' * 320
         for frame in codec.buffer_and_encode(silence):
             codec.decode(frame)
Esempio n. 3
0
 def _test_with_codec(self, codec):
     from shtoom.doug import dtmf
     detect = dtmf.DtmfDetector()
     for k in dtmf.dtmf2freq.keys():
         s = dtmf.dtmfGenerator(k, 320)
         s1, s2 = s[:320], s[320:]
         s1res = []
         s2res = []
         for frame in codec.buffer_and_encode(s1):
             codec.decode(frame)
         for frame in codec.buffer_and_encode(s2):
             codec.decode(frame)
         for frame in codec.buffer_and_encode(s1):
             s1res.append(codec.decode(frame))
         for frame in codec.buffer_and_encode(s2):
             s2res.append(codec.decode(frame))
         self.failUnless(len(s1res) == 1, s1res)
         self.failUnless(len(s2res) == 1, s2res)
         s = s1res[0]+s2res[0]
         digit = detect.detect(s)
         self.assertEquals(k, digit, msg="k: %s, digit: %s, s=%s" % (k, digit, `s`,))
         silence = '\0'*320
         for frame in codec.buffer_and_encode(silence):
             codec.decode(frame)