maaash.jp

what I create

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

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

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

[python]

!/usr/bin/python

# -*- coding: utf-8 -*-

# コマンドラインで指定したskypeidに電話をかける

import Skype4Py
import sys
import os

os.environ[‘DISPLAY’] = ’127.0.0.1:0.0′

# This variable will get its actual value in OnCall handler
CallStatus = 0

# Here we define a set of call statuses that indicate a call has been either aborted or finished
CallIsFinished = set ([Skype4Py.clsFailed, Skype4Py.clsFinished, Skype4Py.clsMissed, Skype4Py.clsRefused, Skype4Py.clsBusy, Skype4Py.clsCancelled]);

def AttachmentStatusText(status):
return skype.Convert.AttachmentStatusToText(status)

def CallStatusText(status):
return skype.Convert.CallStatusToText(status)

# This handler is fired when status of Call object has changed
def OnCall(call, status):
global CallStatus
CallStatus = status
print ‘Call status: ‘ + CallStatusText(status)
if status == Skype4Py.clsInProgress:
print ‘ playing wav’
call.InputDevice( Skype4Py.callIoDeviceTypeFile ,’/home/mash/skype/01_16bit_16kHz.wav’ )

HasConnected = False
def OnInputStatusChanged(call, status):
global HasConnected
print ‘InputStatusChanged: ‘,call.InputDevice(),call,status
print ‘ inputdevice: ‘,call.InputDevice()

# 一度CallInputStatusがTrueになった後、Falseになったら、ファイルの再生が終了してる(はず)
if status == True:
HasConnected = True

if status == False and HasConnected == True:
print ‘ play finished’
call.Finish()

# This handler is fired when Skype attatchment status changes
def OnAttach(status):
print ‘API attachment status: ‘ + AttachmentStatusText(status)
if status == Skype4Py.apiAttachAvailable:
skype.Attach()

# Let’s see if we were started with a command line parameter..
try:
CmdLine = sys.argv[1]
except:
print ‘Missing command line parameter’
sys.exit()

# Creating Skype object and assigning event handlers..
skype = Skype4Py.Skype()
skype.OnAttachmentStatus = OnAttach
skype.OnCallStatus = OnCall
skype.OnCallInputStatusChanged = OnInputStatusChanged

# Starting Skype if it’s not running already..
if not skype.Client.IsRunning:
print ‘Starting Skype..’
skype.Client.Start()

# Attatching to Skype..
print ‘Connecting to Skype..’
skype.Attach()

# Checking if what we got from command line parameter is present in our contact list
Found = False
for F in skype.Friends:
if F.Handle == CmdLine:
Found = True
print ‘Calling ‘ + F.Handle + ‘..’
skype.PlaceCall(CmdLine)
break

if not Found:
print ‘Call target not found in contact list’
sys.exit()

# Loop until CallStatus gets one of “call terminated” values in OnCall handler
while not CallStatus in CallIsFinished:
pass

[/python]

Comments