第一次录音时,软件会请求录音权限,授权允许即可
执行录音操作后,会在后台录制指定时间的脚本,本博客展示的录制音频时间为60秒,录音过程中产生的音频文件不能进行播放,执行录音操作后,会立刻在指定目录产生一个指定名字的音频文件,这个文件想要播放就必须得在执行录音操作后,后台录音达到指定的录音时长,这个产生的音频才能进行播放
录音脚本只是验证录制效果,可以在此基础上进行丰富,让脚本更加灵活
录音命令
1
|
termux-microphone-record
|
录音命令选项介绍
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
-d 使用默认值开始录制
-f 开始录制到特定文件
-l 以指定的限制开始记录(以秒为单位,0 为无限制)
-e 使用指定的编码器开始录制(aac、amr_wb、amr_nb)
-b 以指定的比特率开始录制(以 kbps 为单位)
-r 使用指定的采样率开始记录(以 Hz 为单位)
-c 使用指定的 channel 数开始录制 (1, 2, ...)
-i 获取有关当前录音的信息
-q 退出录音
|
录音操作方法
1
2
3
|
termux-microphone-record -e acc -l 60 -f test.acc
或者
termux-microphone-record -e acc -l 60 -f $HOME/storage/shared/Downloadtest.acc
|
录音脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package_1="termux-api";
# package_1
result=$(pkg list-all | grep -w "$package_1" | tr ' ' '\n' | grep --color=auto -w "installed" | xargs echo);
if [ "$result" != "[installed]" ]; then
pkg install $package_1 -y;
fi
record_time="1800";
let delay="$record_time+1";
savepath="$HOME/storage/shared/Download";
while true
do
if [ $(ps aux | grep "com.termux.api" | grep -v "grep" | awk '{print $11}') ]; then
ps aux | grep "com.termux.api" | grep -v "grep" | awk '{print $11}' | xargs killall;
fi
result=`df -h | grep "block" | awk '{print $5}' | tr '%' ' '`;
if [ "$result" -ge 90 ]; then
find $savepath -mtime +30 -exec rm -rf '{}' \;
else
filename=`date | tr ' ' '-' | tr ':' '-'`;
if [ -d "$savepath" ]; then
date_year=`date | awk '{print $6}'`;
date_month=`date | awk '{print $2}'`;
dir_1=$date_year-$date_month;
if [ -d "$savepath/$dir_1" ]; then
termux-microphone-record -e acc -l $record_time -f $savepath/$dir_1/$filename.acc; sleep $delay; echo "record complate!";
if [ $(ps aux | grep "com.termux.api" | grep -v "grep" | awk '{print $11}') ]; then
ps aux | grep "com.termux.api" | grep -v "grep" | awk '{print $11}' | xargs killall;
fi
else
mkdir -p $savepath/$dir_1;
termux-microphone-record -e acc -l $record_time -f $savepath/$dir_1/$filename.acc; sleep $delay; echo "record complate!";
if [ $(ps aux | grep "com.termux.api" | grep -v "grep" | awk '{print $11}') ]; then
ps aux | grep "com.termux.api" | grep -v "grep" | awk '{print $11}' | xargs killall;
fi
fi
else
mkdir -p $savepath;
fi
fi
done
|