使用什么 ffmpeg 命令将无符号整数列表转换为音频文件?

What ffmpeg command to use to convert a list of unsigned integers into an audio file?

我有一个文件,其中包含大约四万个整数的列表,这些整数是 space 分隔的,每个整数的值都在 0 到 255 之间。就是这个文件:

https://github.com/johnlai2004/sound-project/blob/master/integers.txt

如果您将扬声器连接到 ESP32 分线板,然后 运行 这个整数列表以 24kHz 的频率通过数模转换器,您会听到这句话,"That's not the post that you missed."

我想知道的是如何使用 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 命令之前,我必须先将我的整数列表转换为二进制文件。所以我创建了一个名为 main.go 的 golang 脚本:

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 + 扬声器的输出,这正是我想要的。