【发布时间】:2012-03-23 22:07:40
【问题描述】:
我想使用 Python 编写的 SL4A 应用程序录制 1 秒钟的声音,然后找到声音的最大幅度。
我可以使用 SL4A API 的任何部分或可以使用的 Python API 的任何部分吗?或者我可以为此安装任何 python 模块?
我从 SL4A 搜索了 Python API,但没有找到任何与振幅相关的内容。也许我只是错过了。
更新:
我已设法将wave.py 模块导入我的代码并尝试打开记录的文件。但是当我访问
wave.open("/sdcard/sl4aTemp/sound_sample.wav")
它会抛出这个错误,
File does not start with RIFF id
对于那些好奇我的代码在这里看起来如何的人:
import android, audioop, time, wave
droid = android.Android()
print "Recording starts in: "
for i in range(0,5):
time.sleep(1)
print str(5-i)
time.sleep(1)
print "Speak!"
droid.recorderStartMicrophone('/sdcard/sl4aTemp/sound_sample.wav')
time.sleep(3)
droid.recorderStop()
print "Processing file in:"
for i in range(0,3):
print str(3-i)
time.sleep(1)
filename = "/sdcard/sl4aTemp/sound_sample.wav"
if wave.open(filename,"r") == True:
print "Processing " + filename
else:
print "File not processed"
FILE=wave.open(filename,"r")
rez=FILE.readframes(30)
print str(rez)
【问题讨论】:
标签: android python audio sl4a amplitude