audio - 使用什么 ffmpeg 命令将无符号整数列表转换为音频文件?
问题描述
我有一个文件,其中包含大约四万个用空格分隔的整数的列表,每个整数的值在 0 到 255 之间。这里是这个文件:
https://github.com/johnlai2004/sound-project/blob/master/integers.txt
如果您将扬声器连接到 ESP32 分线板,然后以 24kHz 的频率通过数模转换器运行此整数列表,您将听到一句话,“这不是您错过的帖子。”
我想知道的是您如何使用 FFMPEG 将此整数列表转换为其他计算机可以播放以听到相同短语的声音文件?我试过这个命令:
ffmpeg -f u8 -ac 1 -ar 24000 -i integers.txt -y audio.wav
但我audio.wav
只是听起来像白噪音。-f
我为和尝试了其他一些值-ar
,但我听到的只是不同频率的白噪声,可能还有一些额外的嗡嗡声。
是否可以使用 ffmpeg 将我的整数列表转换为音频文件供其他计算机播放?如果是这样,执行此操作的正确 ffmpeg 命令是什么?
其他说明
如果有帮助,如果我想听音频,这是我上传到 ESP32 的草图文件:
https://github.com/johnlai2004/sound-project/blob/master/play-audio.ino
简而言之,该文件如下所示:
#define speakerPin 25 //The pins to output audio on. (9,10 on UNO,Nano)
#define bufferTotal 1347
#define buffSize 32
byte buffer[bufferTotal][buffSize];
int buffItemN = 0;
int bufferN = 0;
hw_timer_t * timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
void IRAM_ATTR onTimer() {
portENTER_CRITICAL_ISR(&timerMux);
byte v = buffer[bufferN][buffItemN];
dacWrite(speakerPin,v);
buffItemN++;
if(buffItemN >= buffSize){ //If the buffer is empty, do the following
buffItemN = 0; //Reset the sample count
bufferN++;
if(bufferN >= bufferTotal)
bufferN = 0;
}
portEXIT_CRITICAL_ISR(&timerMux);
}
void setup() {
/* buffer records */
buffer[0][0]=88; // I split the long list of integers and load it into a 2D array
buffer[0][1]=88;
buffer[0][2]=86;
buffer[0][3]=85;
//etc....
buffer[1346][28]=94;
buffer[1346][29]=92;
buffer[1346][30]=92;
buffer[1346][31]=95;
/* end buffer records */
timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &onTimer, true);
timerAlarmWrite(timer, 41, true);
timerAlarmEnable(timer);
}
void loop() {
}
这buffer...
是在integers.txt
文件中找到的整数列表。
解决方案
正如@Gyan 在评论中建议的那样,在运行 ffmpeg 命令之前,我必须先将我的整数列表转换为二进制文件。所以我创建了一个用这个调用的 golang 脚本main.go
:
package main
import (
"io/ioutil"
"strings"
"strconv"
"os"
)
func main() {
input:="./integers.txt"
output:="./binary.raw"
// Load the list of integers into memory
contentbyte, _ := ioutil.ReadFile(input)
content := strings.Split(string(contentbyte)," ");
// Prepare to output a new binary file
f, err := os.OpenFile(output, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
panic(err)
}
defer f.Close()
for _,val := range content {
// Convert each integer to a binary value and write to output file
i,_ := strconv.Atoi(val)
if _, err = f.Write([]byte{byte(i)}); err != nil {
panic(err)
}
}
}
我运行go run main.go
给我binary.raw
文件。然后我运行了 ffmpeg 命令,正如我在这样的问题中发布的那样ffmpeg -f u8 -ar 24000 -ac 1 -i binary.raw -y audio.wav
。
该audio.wav
文件听起来就像我的 ESP32 + 扬声器的输出,这正是我想要的。
推荐阅读
- roles - 选择角色的不同方式
- c# - 当页面视频全屏时,将 Webview2 切换到全屏
- r - 如何正确使用 GET 和 httr 结构相同的两个 cookie?
- javascript - Javascript 中的过滤器方法不起作用。但其他过滤方法正在工作
- python - 如何在从串口接收的文本浏览器 pyqt5 上附加串行数据 python pyqt
- javascript - 有没有办法根据对象内部已经存在的两个值在对象内部创建新的键值对?- JavaScript
- php - 无法在 Dockerized 应用程序中使用 DBGp 从远程服务器将 Xdebug 重定向到 localhost
- google-analytics - 如何使用 gtag 脚本手动设置 Google Analytics(分析)引荐来源网址?
- c - 如何使“long tv_nsec”和“time_t tv_sec”兼容?
- php - 在 laravel 中使用 DB Facade 时我无法访问模型方法