Supabase's newly uploaded audio blobs are experiencing difficulties when it comes to

I've integrated Supabase storage for storing audio blobs. After retrieving the blob from an API call, it is uploaded successfully to the storage bucket. However, when attempting to play the audio file, nothing happens and the duration shows as 0:00. Strangely, manually uploading an mp3 file displays a proper duration like 1:29 and plays without issues. Below is the code snippet responsible for this functionality. I'm keen on saving these blobs to a database to avoid unnecessary API calls.

const getAudio = async (message) => {
console.log("called");
const data = {
  text: "hi",
  voice_settings: {
    stability: 0,
    similarity_boost: 0,
  },
};

const config = {
  headers: {
    "xi-api-key": process.env.API_KEY,
  },
  responseType: "blob",
};
try {
  const voiceResponse = await axios.post(
    "https://api.elevenlabs.io/v1/text-to-speech/XXXXXXXXXXX",
    data,
    config
  );

  console.log(voiceResponse.data);

  blob = new Blob([voiceResponse.data], { type: "audio/mpeg" });
  console.log("=========================================");
  console.log(blob);

  const response = await supabase.storage
    .from("audio_blobs")
    .upload(email + "/" + "audio.mp3", blob, {
      contentType: "audio/mpeg",
    });

  if (response.error) {
    console.log(response.error);
  } else {
    console.log("success");
  }

} catch (err) {
  console.log(err);
}

}; getAudio()

Answer №1

As per the information provided in the official documentation:

When dealing with React Native, it is important to note that using Blob, File or FormData may not yield the desired results. Instead, consider uploading files using ArrayBuffer generated from base64 file data as demonstrated below.

To accomplish this, retrieve the file in mp3 format and utilize an array buffer:

import { decode } from 'base64-arraybuffer'
// (...)
const { data, error } = await supabase
  .storage
  .from('avatars')
  .upload('email'+ "/" + "audio.mp3", decode('mp3_file'), {
    contentType: 'audio/mpeg'
  })

Answer №2

If you want to store audio blobs in your Supabase bucket, one way to do it is by creating a Supabase client within your component and uploading the audio file from there.

Here's how you can set up the Supabase client:

import { createClient } from "@supabase/supabase-js";

const supabase = createClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL || "",
    process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || ""
);

Now, let's send the audio file to the designated folder:

const file = new File(recordingBuffer, "recording.mp3", {
    type: recordingBlob.type,
});

const { data, error } = await supabase.storage
    .from("Recordings")
    .upload("clientside", file, {
        contentType: "audio/mpeg",
    });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Angular $digest cycle ensures that the entire view is refreshed, rather than just a portion

Encountering a peculiar problem in Angular 1 where the script is getting stuck in an endless loop, eventually causing the browser to freeze. Here's what I'm attempting: <script> $scope.A = true; $scope.B = [{blah},{blah}]; $sc ...

I was caught off guard by the unusual way an event was used when I passed another parameter alongside it

One interesting thing I have is an event onClick that is defined in one place: <Button onClick={onClickAddTopics(e,dataid)} variant="fab" mini color="primary" aria-label="Add" className={classes.button}> <AddIcon /> & ...

Exploring Grails Assets, Redirections, Secure Sockets Layer, and Chrome

Using Grails 2.1.1 with the resources plugin, I have encountered an issue when incorporating the jstree library which comes with themes configuration: "themes":{ "theme":"default", "dots":false, "icons":true } The JavaScript in the library locat ...

When iterating over objects in JavaScript, the loop may return undefined, while using Lodash's map

After encountering an issue with a JavaScript loop where the value was returning as null upon completion, I decided to try using lodash for the same purpose and it successfully returned the result. This is what I attempted: JavaScript: const jsRows = Ob ...

What is the best way to retrieve a {collection object} from a JavaScript map?

My application utilizes a third-party library that returns the map in the following format: public sids: Map<SocketId, Set<Room>> = new Map(); When I try to access it using the code below: io.of("/").adapter.sids.forEach(function(va ...

Unable to retrieve innerHTML from a jQuery element

My current task involves implementing the Google Maps API. The code snippet below is what I have written so far: <div id="map"></div> To inspect the content of $("div#map"), I am utilizing the Google Chrome console. console.log($("div#map")) ...

Guide on making jQuery color variables?

Is there a way to achieve CSS variable-like functionality with jQuery? For example, creating reusable CSS attributes in jQuery instead of using SASS variables. Imagine if I could define a variable for the color black like this: I want to make a variable t ...

Protractor: Saving data locally with local storage - A step-by-step guide

I've come across several instances of retrieving previously saved information, but I haven't found any examples of retrieving stored values. ...

What is the best way to create this server backend route?

I'm currently working on a fullstack project that requires a specific sequence of events to take place: When a user submits an event: A request is sent to the backend server The server then initiates a function for processing This function should ru ...

vue.js libs requiring "new ..." are being scolded by eslint for their misspelling

When working with Vue libraries, such as Swiper, that require the use of 'new …' in the script section, I encounter ESlint errors no matter how I try to write it. Even though 'new ...' works perfectly fine in the frontend, ESlint cont ...

Unable to display tags with /xoxco/jQuery-Tags-Input

I'm experimenting with the tagsinput plugin in a textarea located within a div that is loaded using the jquery dialog plugin. The specific plugin I am using is /xoxco/jQuery-Tags-Input. After checking that the textarea element is ready, I noticed th ...

Creating raw JavaScript from npm package:How to convert npm modules into plain

Is there a way to get a pre-compiled plain JavaScript file from the repository https://github.com/airbrake/airbrake-js? I'm looking for a solution without using bower, npm or any other tools - just a single JavaScript file. By the way: The file "http ...

Issues with implementing KendoUI's datepicker in conjunction with Angular

My index.html file contains the following imports: <script src="content/js/angular.js"></script> <link href="content/js/kendo.common-material.min.css" rel="stylesheet" /> <link href="content/js/kendo.material.min.css" rel="styleshe ...

What happens with the styling in this project when the CSS file is blank?

As a first-year CS student in university, I have been diving into the world of React.js. Currently, I am exploring a resume project and noticed that both app.js and index.js files are empty. I am curious to know how the styling is achieved in this project. ...

Facing issues with Laravel errors preventing the implementation of CSS on my localhost

These are the tailwindcss errors I am encountering: npm WARN @tailwindcss/[email protected] requires a peer of tailwindcss@^1.0 but none is installed. You must install peer dependencies yourself. npm WARN @tailwindcss/[email protected] requi ...

What is the best way to display a form within every row of a data table?

I am currently working on a page that retrieves data from a backend and displays it in a Datatable. One of the columns in my table is an input field with a default value fetched from the backend, and another column contains buttons. How can I implement a f ...

Tips for minimizing the need to copy the entire dojo library each time you create a new Java EE package for deployment on GlassFish

Currently, I am diving into comet programming and utilizing the cometd implementation along with the JavaScript dojo library before deploying my war files to GlassFish. The issue I have encountered is that every time I create a new project, I find myself i ...

In what way does getStaticProps() display retrieved data within the original HTML document?

Upon reviewing information from the Next.js official website, it is revealed that pre-rendered pages initially showcase the pre-rendered HTML before being hydrated by initializing React components and enabling interactivity through event listeners. In li ...

What are the steps to customizing a package on atmospherejs.com within meteor.js?

When working with atmosphere in meteor.js, installing a package is typically as simple as using a single command. However, if there is a need to make changes to a specific package for customization purposes, the process becomes a bit more complex. For ex ...

When a card is clicked in the parent component, data is sent to the child component in Angular. The card contains an image, name, ID,

How can I pass data from a parent component (nfts) to a child component (main) when a card is clicked? The card contains images, ids, names, and more information. I've attempted using @Input() but haven't been able to receive the value in the ch ...