[skype api]skypeで電話をかけ指定のwavを再生して切断

Posted on 7月 1, 2008
Filed Under skype4py, python, skype |

skypeで電話をかけ指定のwavを再生して切断。
フレームレート16kHz、16bitサンプリングのwavを再生できる。
44.1kHzのはNGでした。
skypeは
DISPLAY=127.0.0.1:0.0
で立ち上がっている。

再生できるんだけど、
再生開始後の数秒間、音程が異常に崩れる。。
なんかおまじないがあるのかなぁ

PYTHON:
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # コマンドラインで指定したskypeidに電話をかける
  5.  
  6. import Skype4Py
  7. import sys
  8. import os
  9.  
  10. os.environ['DISPLAY'] = '127.0.0.1:0.0'
  11.  
  12. # This variable will get its actual value in OnCall handler
  13. CallStatus = 0
  14.  
  15. # Here we define a set of call statuses that indicate a call has been either aborted or finished
  16. CallIsFinished = set ([Skype4Py.clsFailed, Skype4Py.clsFinished, Skype4Py.clsMissed, Skype4Py.clsRefused, Skype4Py.clsBusy, Skype4Py.clsCancelled]);
  17.  
  18. def AttachmentStatusText(status):
  19.    return skype.Convert.AttachmentStatusToText(status)
  20.  
  21. def CallStatusText(status):
  22.     return skype.Convert.CallStatusToText(status)
  23.  
  24. # This handler is fired when status of Call object has changed
  25. def OnCall(call, status):
  26.     global CallStatus
  27.     CallStatus = status
  28.     print 'Call status: ' + CallStatusText(status)
  29.     if status == Skype4Py.clsInProgress:
  30.         print ' playing wav'
  31.         call.InputDevice( Skype4Py.callIoDeviceTypeFile ,'/home/mash/skype/01_16bit_16kHz.wav' )
  32.  
  33. HasConnected = False
  34. def OnInputStatusChanged(call, status):
  35.     global HasConnected
  36.     print 'InputStatusChanged: ',call.InputDevice(),call,status
  37.     print ' inputdevice: ',call.InputDevice()
  38.  
  39.     # 一度CallInputStatusがTrueになった後、Falseになったら、ファイルの再生が終了してる(はず)
  40.     if status == True:
  41.         HasConnected = True
  42.  
  43.     if status == False and HasConnected == True:
  44.         print ' play finished'
  45.         call.Finish()
  46.  
  47. # This handler is fired when Skype attatchment status changes
  48. def OnAttach(status):
  49.     print 'API attachment status: ' + AttachmentStatusText(status)
  50.     if status == Skype4Py.apiAttachAvailable:
  51.         skype.Attach()
  52.  
  53. # Let's see if we were started with a command line parameter..
  54. try:
  55.     CmdLine = sys.argv[1]
  56. except:
  57.     print 'Missing command line parameter'
  58.     sys.exit()
  59.  
  60. # Creating Skype object and assigning event handlers..
  61. skype = Skype4Py.Skype()
  62. skype.OnAttachmentStatus = OnAttach
  63. skype.OnCallStatus = OnCall
  64. skype.OnCallInputStatusChanged = OnInputStatusChanged
  65.  
  66. # Starting Skype if it's not running already..
  67. if not skype.Client.IsRunning:
  68.     print 'Starting Skype..'
  69.     skype.Client.Start()
  70.  
  71. # Attatching to Skype..
  72. print 'Connecting to Skype..'
  73. skype.Attach()
  74.  
  75.  
  76. # Checking if what we got from command line parameter is present in our contact list
  77. Found = False
  78. for F in skype.Friends:
  79.     if F.Handle == CmdLine:
  80.         Found = True
  81.         print 'Calling ' + F.Handle + '..'
  82.         skype.PlaceCall(CmdLine)
  83.         break
  84.  
  85. if not Found:
  86.     print 'Call target not found in contact list'
  87.     sys.exit()
  88.  
  89. # Loop until CallStatus gets one of "call terminated" values in OnCall handler
  90. while not CallStatus in CallIsFinished:
  91.     pass

Comments

One Response to “[skype api]skypeで電話をかけ指定のwavを再生して切断”

  1. mash on 7月 5th, 2008 11:21

    音質が悪いのは気のせいだ、というか音源のせいだ。
    skypeAPIでは、16bit,16kHz,monoのwavしか入力ファイルとして設定できなくて、
    音楽をmp3→wavして聴いてみたらひどかったけど、
    こえ部の人の声にしてみたらなんとかなるなぁ。

Leave a Reply