问题描述
我有这个基本的 python 脚本 {test.py} 来读取音频文件并检查其中是否有任何声音或只是空白(空)并返回如下结果:
#!/usr/bin/python
import soundfile as np
import os
import sys
import shutil
from asterisk.agi import *
user='asterisk'
path = '/var/spool/asterisk/monitor/'
source = '/'
dst = 'deleted/scanned-'
source_path = path + source
dst_path = path + dst
files = []
for dirname,dirnames,filenames in os.walk(source_path):
for filename in filenames:
if 'aif' in filename or 'wav' in filename:
if 'asd' not in filename:
print os.path.join(dirname,filename)
files.append(filename)
for f in files:
x,fs = np.read(source_path + f)
vol_rms = x.max()
print ('file name: ' + f)
print vol_rms
if vol_rms <= 0.001244140625:
print '----------------------------------'
print 'no sound in this file'
print '----------------------------------'
#print vol_rms
print 'MOVE: ',source_path + f
print 'DST: ',dst_path + f
shutil.move(source_path + f,dst_path + f)
print '----------------------------------'
elif vol_rms > 0.001244140625:
print '----------------------------------'
print ('Full of sound')
print '----------------------------------'
我的拨号方案:
[filter]
exten => 100,1,NoOp(### ----- TEST PYTHON SCRIPT ----- ###)
same => n,Answer()
same => n,Monitor(wav,${UNIQUEID},o)
same => n,Playback(hello-world)
same => n,Wait(3)
same => n,StopMonitor(${UNIQUEID})
same => n,AGI(test.py)
same => n,NoOp(1,result is: ${result})
same => n,GotoIf($["${result}" = "no sound"]?dial1)
same => n,GotoIf($["${result}" = "full of sound"]?filter:dial2)
same => n(dial1),Dial(${SPHONE1},15,rt)
same => n,Hangup()
same => n(dial2),Dial(${SPHONE2},Hangup( BYE 1)
在执行脚本时,它会扫描整个文件夹 /var/spool/asterisk/monitor/ 寻找 wav 文件并扫描它们以检测它们是否有声音。到目前为止工作正常。
我想要的:
我希望脚本只读取 wav 文件 ${UNIQUEID} 变量。然后在我的脚本中声明第二个变量作为结果,并将其作为 {$results} 传回拨号计划。
软件和硬件:
星号 16.16.0 蟒蛇 2.7.17 ubuntu 18.04 LTS 仿生
内存:8Gb cpu:i5
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)