2025-04-19 22:11:57 +08:00
|
|
|
// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
2025-04-24 15:41:33 +08:00
|
|
|
import { resolveServiceURL } from "./resolve-service-url";
|
2025-04-22 11:03:53 +08:00
|
|
|
|
2025-04-19 22:11:57 +08:00
|
|
|
export async function generatePodcast(content: string) {
|
2025-04-24 15:41:33 +08:00
|
|
|
const response = await fetch(resolveServiceURL("podcast/generate"), {
|
|
|
|
|
method: "post",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
2025-04-19 22:11:57 +08:00
|
|
|
},
|
2025-04-24 15:41:33 +08:00
|
|
|
body: JSON.stringify({ content }),
|
|
|
|
|
});
|
2025-04-19 22:11:57 +08:00
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
const arrayBuffer = await response.arrayBuffer();
|
|
|
|
|
const blob = new Blob([arrayBuffer], { type: "audio/mp3" });
|
|
|
|
|
const audioUrl = URL.createObjectURL(blob);
|
|
|
|
|
return audioUrl;
|
|
|
|
|
}
|