Asterisk无法使用python运行agi脚本

时间:2017-07-03 02:34:09

标签: python python-2.7 asterisk

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

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))

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

1 个答案:

答案 0 :(得分:0)

#include <stdio.h>
#include <stdint.h>
#include <math.h>

#define N 44100

void main()
{
// Create audio buffer
int16_t buf[N] = {0}; // buffer
int n;                // buffer index
double Fs = 44100.0;  // sampling frequency

// Generate 1 second of audio data - it's just a 1 kHz sine wave
for (n=0 ; n<N ; ++n) buf[n] = 16383.0 * sin(n*1000.0*2.0*M_PI/Fs);

// Pipe the audio data to ffmpeg, which writes it to a wav file
FILE *pipeout;
pipeout = popen("ffmpeg -y -f s16le -ar 44100 -ac 1 -i - beep.wav", "w");
fwrite(buf, 2, N, pipeout);
pclose(pipeout);
}

尝试>>> 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