Asterisk无法使用python运行agi script



我创建了python脚本来运行一些任务。 当我通过python编译执行此脚本时,它就像一个魅力。

python test.py

但是当我从Asterisk agi拨打 test.py 时,我无法获得时间戳。

exten => 201,n,agi(test.py,"おはようございます")

test.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
from datetime import datetime
import time
import sys
#from asterisk.agi import *
#agi = AGI()
#agi.verbose("python agi started")
#agi.verbose("params : " +agi.env['agi_arg_1'])
open_jtalk = ['open_jtalk']
mech = ['-x', '/home/linuxbrew/.linuxbrew/Cellar/open-jtalk/1.10_1/dic']
htsvoice = ['-m', '/home/linuxbrew/.linuxbrew/Cellar/open-jtalk/1.10_1/voice/mei/mei_normal.htsvoice']
speed = ['-r', '1.0']
print "nothing to lose"
timestamp = int(round(time.time() * 1000))
print "time : " + timestamp
file_name = 'tts_output' + str(timestamp) + '.wav'
file_name_output = 'tts_output' + str(timestamp) + '_8000.wav'
outwav = ['-ow', '/var/lib/asterisk/agi-bin/' + file_name]
cmd = open_jtalk + mech + htsvoice + speed + outwav
print "cmd : "
c = subprocess.Popen(cmd, stdin=subprocess.PIPE)
c.stdin.write("おはようございます")
c.stdin.close()
c.wait()
print "AAAAAAA"
#agi.verbose("command line is completed")
sox = ['sox']
samplerate = ['-r', '8000']
file_input = [file_name]
file_output = [file_name_output]
sox_command = sox  + file_input + samplerate + file_output
ds = subprocess.Popen(sox_command)
ds.wait()

test.py 运行时,控制台打印为"没有什么可丢失的",但下一个命令无法执行。

timestamp = int(round(time.time() * 1000))

有人可以帮助我吗?任何帮助将不胜感激!

>>> import time
>>> timestamp = int(round(time.time() * 1000))
>>> print "time : " + timestamp
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects

试试print "time : {}".format(timestamp)

最新更新