Eli7
Eli7

Reputation: 31

Google Drive create AudioBuffer from a WAV file in Google Drive. webContentLink field not available

I have to process many wav files from Google drive, so I need to obtain the audioBuffers: I'm trying this code, but return the error:

TypeError: response.body.getReader is not a function

The code I'm trying:

  const query = `parents='${folderId}' and mimeType = 'audio/wav'`; //
  const response = await gapi.client.drive.files.list({
    q: query,
    supportsAllDrives: true,
    includeItemsFromAllDrives: true,
  });
  const files = response.result.files;
  console.log("AUDIO files: ", files);
  // Use the Web Audio API to merge the audio files.
  const context = new AudioContext();
  const channel0Buffers = [];
  const channel1Buffers = [];

  for (let i = 0; i < files.length; i++) {
    const file = files[i];
    const fileId = file.id;
    const response = await gapi.client.drive.files.get({
      fileId: fileId,
      alt: "media",
      supportsAllDrives: true,
      includeItemsFromAllDrives: true,
      responseType: "stream",
    });
    const reader = response.body.getReader();
    const streamSource = context.createMediaStreamSource(
      new MediaStream([
        {
          read: async function () {
            const { done, value } = await reader.read();
            if (done) {
              return null;
            }
            return value.buffer;
          },
        },
      ])
    );
    const audioBuffer = await context.decodeAudioData(streamSource);
    if (i < 2) {
      channel0Buffers.push(audioBuffer);
    } else {
      channel1Buffers.push(audioBuffer);
    }

I noticed that the webContentLink field that is a link for downloading the content of the file in a browser is not available for my wav files. Any help will be appreciated. Thanks

Upvotes: 1

Views: 59

Answers (0)

Related Questions