0
votes

I have the code below that converts audio files to .wav in react:

const [filename, setFilename] = useState(null)
  const [file, setFile] = useState(null)
  const [message, setMessage] = useState(null)
  const [audioSrc, setAudioSrc] = useState(null)
  const ffmpeg = createFFmpeg({
    corePath: 'https://unpkg.com/@ffmpeg/[email protected]/dist/ffmpeg-core.js',
    log: true,
  });

  const doTranscode = async () => {
    setMessage('Loading ffmpeg-core.js');
    await ffmpeg.load();
    setMessage('Start transcoding');
    ffmpeg.FS('writeFile', filename, await fetchFile(file));
    await ffmpeg.run('-i', filename, 'test.wav');
    setMessage('Complete transcoding');
    const data = ffmpeg.FS('readFile', 'test.wav');
    setAudioSrc(URL.createObjectURL(new Blob([data.buffer], { type: 'audio/wav' })));
    console.log(audioSrc)
  };

  useEffect(() => {
    if (file) {
      doTranscode()
    }
  }, [file])

  //ffmpeg -i input.mp3 -acodec pcm_s16le -ac 1 -ar 16000 output.wav
  const onDrop = useCallback(acceptedFile => {
    setFilename(acceptedFile[0].name)
    setFile(acceptedFile[0])
    console.log(acceptedFile[0])
    // console.log(acceptedFile)
  }, [])

I was wondering at what point I would be able to upload the file to s3 using this code from a tutorial:

s3 code

To rephrase, I am unsure where the converted .wav file lies. I need to know what variable it is stored in at what point to pass it to s3.

Thanks