triple._.a
TTCTheo's Typesafe Cult
•Created by triple._.a on 1/19/2024 in #questions
Upload a buffer to UploadThing?
Solution
// text-to-speech.ts
"use server";
import { utapi } from "@/app/api/uploadthing/route";
export const textToSpeech = async (text: string) => {
const data = {
model_id: "eleven_monolingual_v1",
text,
voice_settings: {
similarity_boost: 0.5,
stability: 0.5,
},
};
const response = await fetch(
`https://api.elevenlabs.io/v1/text-to-speech/piTKgcLEGmPE4e6mEKli`,
{
method: "POST",
headers: {
"Access-Control-Allow-Origin": "*",
"xi-api-key": process.env.ELEVEN_LABS_API_KEY!,
"Content-Type": "application/json",
},
body: JSON.stringify(data),
}
);
if (!response.ok) {
throw new Error("Something went wrong");
}
const arrayBuffer = await response.arrayBuffer();
const blob = new Blob([arrayBuffer], { type: "audio/mpeg" });
const uploadedFile = await utapi.uploadFiles(blob);
return {
data: {
fileUrl: uploadedFile.data?.url,
},
};
};
// text-to-speech.ts
"use server";
import { utapi } from "@/app/api/uploadthing/route";
export const textToSpeech = async (text: string) => {
const data = {
model_id: "eleven_monolingual_v1",
text,
voice_settings: {
similarity_boost: 0.5,
stability: 0.5,
},
};
const response = await fetch(
`https://api.elevenlabs.io/v1/text-to-speech/piTKgcLEGmPE4e6mEKli`,
{
method: "POST",
headers: {
"Access-Control-Allow-Origin": "*",
"xi-api-key": process.env.ELEVEN_LABS_API_KEY!,
"Content-Type": "application/json",
},
body: JSON.stringify(data),
}
);
if (!response.ok) {
throw new Error("Something went wrong");
}
const arrayBuffer = await response.arrayBuffer();
const blob = new Blob([arrayBuffer], { type: "audio/mpeg" });
const uploadedFile = await utapi.uploadFiles(blob);
return {
data: {
fileUrl: uploadedFile.data?.url,
},
};
};
// upload-file.ts
"use server";
import { utapi } from "@/app/api/uploadthing/route";
export async function uploadFile(file: Buffer) {
const response = await utapi.uploadFiles(file);
return response.data?.url;
}
// upload-file.ts
"use server";
import { utapi } from "@/app/api/uploadthing/route";
export async function uploadFile(file: Buffer) {
const response = await utapi.uploadFiles(file);
return response.data?.url;
}
3 replies
TTCTheo's Typesafe Cult
•Created by triple._.a on 1/19/2024 in #questions
Upload a buffer to UploadThing?
I DID IT OMG WHAAAT
3 replies