我想使用 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)