Speech to Notion - File conversion AIF to MP3 (Olympus 9500)

Dear all,

I have successfully implemented the Thomas Frank workflow. However, I am using an Olypmus voice recorder that I am using for this automation - The device records in a dedicated file format which can be converted automatically by plugging the device to the PC (.AIF).
As this file is not readable by Whisper, it needs to be converted. I was trying to include cloudconvert, but the code I have seems to be not functional. Kindly request your support.


const cloudconvert = new (require('cloudconvert'))('dein_cloudconvert_api_key');
const fs = require('fs');
const path = require('path');
const axios = require('axios');

const convertFile = async (inputFilePath) => {
    let job = await cloudconvert.jobs.create({
        tasks: {
            'import-my-file': {
                operation: 'import/upload'
            },
            'convert-my-file': {
                operation: 'convert',
                input: 'import-my-file',
                input_format: 'aiff',
                output_format: 'mp3'
            },
            'export-my-file': {
                operation: 'export/url',
                input: 'convert-my-file'
            }
        }
    });

    // Lade die AIFF-Datei hoch
    let uploadTask = job.tasks.filter(
        task => task.name === 'import-my-file'
    )[0];
    let formData = new FormData();
    formData.append('file', fs.createReadStream(inputFilePath));
    await cloudconvert.tasks.upload(uploadTask, formData);

    // Warte auf Job-Ende
    job = await cloudconvert.jobs.wait(job.id);

    // Lade die konvertierte MP3-Datei herunter
    let exportTask = job.tasks.filter(
        task => task.operation === 'export/url'
    )[0];
    let resultFiles = exportTask.result.files;
    let fileUrl = resultFiles[0].url;

    const response = await axios.get(fileUrl, { responseType: 'stream' });
    const writer = fs.createWriteStream(inputFilePath); // überschreibt die ursprüngliche Datei
    response.data.pipe(writer);

    return new Promise((resolve, reject) => {
        writer.on('finish', resolve);
        writer.on('error', reject);
    });
};

// Dateipfad aus vorherigem Schritt
const aiffFilePath = this.filePath;  // Datei aus Google Drive heruntergeladen

// Konvertiere Datei und überschreibe ursprüngliche Datei
await convertFile(aiffFilePath);
$.export("$summary", `Successfully converted the file from AIFF to MP3 format.`);

++ how the implementation is planned to work

Hi @balu2910, welcome to Pipedream!
Thank you sharing the detailed information.

Just to make sure, is your code wrapped in a Pipedream Component Step Structure?
I asked @pi, Pipedream’s custom bot, on Slack and it was able to transform your code into a Pipedream component:

import { axios } from "@pipedream/platform";
import cloudconvert from "cloudconvert";

export default defineComponent({
  props: {
    cloudconvertApiKey: {
      type: "string",
      label: "CloudConvert API Key",
      secret: true,
    },
    aiffFileUrl: {
      type: "string",
      label: "AIFF File URL",
    },
  },
  async run({ $ }) {
    const cloudconvertInstance = new cloudconvert(this.cloudconvertApiKey);

    const response = await axios($, {
      method: "GET",
      url: this.aiffFileUrl,
      responseType: "arraybuffer",
    });

    const job = await cloudconvertInstance.jobs.create({
      tasks: {
        "import-my-file": {
          operation: "import/upload",
        },
        "convert-my-file": {
          operation: "convert",
          input: "import-my-file",
          input_format: "aiff",
          output_format: "mp3",
        },
        "export-my-file": {
          operation: "export/url",
          input: "convert-my-file",
        },
      },
    });

    const uploadTask = job.tasks.filter((task) => task.name === "import-my-file")[0];
    await cloudconvertInstance.tasks.upload(uploadTask, response.data);

    const updatedJob = await cloudconvertInstance.jobs.wait(job.id);
    const exportTask = updatedJob.tasks.filter((task) => task.operation === "export/url")[0];
    const resultFiles = exportTask.result.files;
    const mp3FileUrl = resultFiles[0].url;

    return {
      message: "Successfully converted the file from AIFF to MP3 format.",
      mp3FileUrl,
    };
  },
});

Can you please test it and report any errors you may receive?

@andrewcturing Thanks for your support! Tried again and also tried to enable the direct upload from the /temp folder, as well as a direct download back to the /temp folder, overwriting the original .aiff file with the .mp3 file to take this data to Whisper. I still got some errors.

import { axios } from "@pipedream/platform";
import cloudconvert from "cloudconvert";
import fs from "fs";
import stream from "stream";
import { promisify } from "util";
import got from "got";
import FormData from "form-data";


export default defineComponent({
  async run({ steps, $ }) {
    const formData = new FormData();
    formData.append("file", fs.createReadStream('/tmp/file.pdf'));
    const headers = formData.getHeaders();

    const config = {
      method: "POST",
      url: "https://example.com",
      headers,
      data: formData,
    };
    return await axios(config);
  }
});



export default defineComponent({
  props: {
    cloudconvertApiKey: {
      type: "string",
      label: "CloudConvert API Key",
      secret: true,
    },
    aiffFileUrl: {
      type: "string",
      label: "AIFF File URL",
    },
  },
  async run({ $ }) {
    const cloudconvertInstance = new cloudconvert(this.cloudconvertApiKey);

    const response = await axios($, {
      method: "GET",
      url: this.aiffFileUrl,
      responseType: "arraybuffer",
    });

    const job = await cloudconvertInstance.jobs.create({
      tasks: {
        "import-my-file": {
          operation: "import/upload",
        },
        "convert-my-file": {
          operation: "convert",
          input: "import-my-file",
          input_format: "aiff",
          output_format: "mp3",
        },
        "export-my-file": {
          operation: "export/url",
          input: "convert-my-file",
        },
      },
    });

    const uploadTask = job.tasks.filter((task) => task.name === "import-my-file")[0];
    await cloudconvertInstance.tasks.upload(uploadTask, response.data);

    const updatedJob = await cloudconvertInstance.jobs.wait(job.id);
    const exportTask = updatedJob.tasks.filter((task) => task.operation === "export/url")[0];
    const resultFiles = exportTask.result.files;
    const mp3FileUrl = resultFiles[0].url;

    


export default defineComponent({
  async run({ steps, $ }) {
    // Download the webpage HTML file to /tmp
    const pipeline = promisify(stream.pipeline);
    return await pipeline(
      got.stream("https://example.com"),
      fs.createWriteStream('/tmp/file.html')
    );
  }
})


  },
});

What are the errors you are facing?