生成播客(API 方法)
Gemini Enterprise 提供了一项 API,可让您根据源文档生成播客。输出与最终用户可以在笔记本中生成的播客非常相似。
通过 API 生成播客非常适合批量作业,在这些作业中,您可能有数十本或数百本图书、文章或课程,并且希望为每项内容生成一个播客。
Podcast API 是一种独立 API。也就是说,您不需要 NotebookLM Enterprise 笔记本、Gemini Enterprise 许可或数据存储区。您只需拥有已启用的 Google Cloud 项目和“Podcast API 用户”角色。
该 API 的输入是一个 context
元素的数组。这是生成播客所依据的源材料。输入内容可以是文本、图片、音频和视频。上下文数组的总内容必须少于 10 万个令牌。
如需查看支持的类型列表,请参阅本页面上有关 Gemini 2.5 Flash 的图片、文档、视频和音频技术规范。
输出
API 的输出是 MP3 格式的播客。
准备工作
在使用该 API 生成播客之前,您必须具备以下条件:
根据上下文输入生成播客
使用以下命令通过调用 podcast 方法生成播客。
输入是一个多媒体对象数组,例如文本、图片以及音频和视频片段。
REST
如需生成和导出播客,请执行以下操作:
运行以下 curl 命令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/podcasts" \
-d '{
"podcastConfig": {
"focus": "FOCUS",
"length": "LENGTH",
"languageCode": "LANGUAGE_CODE"
},
"contexts": [
{
"MEDIA_TYPE_1": "MEDIA_CONTENT_1"
},
{
"MEDIA_TYPE_2": "MEDIA_CONTENT_2"
}
],
"title": "PODCAST_TITLE",
"description": "PODCAST_DESCRIPTION"
}'
替换以下内容:
PROJECT_ID
:您的项目的 ID。
FOCUS
:一个提示,用于建议播客的重点。
LENGTH
:有两种选择:
SHORT
(通常为 4-5 分钟)
STANDARD
(通常约为 10 分钟,但如果数据集较小,则可能更短)
LANGUAGE_CODE
:可选。指定播客的语言代码。使用 BCP47 定义的语言标记。如果未提供语言代码,则以英语生成播客。
MEDIA_TYPE_N
:指定您用于生成播客的媒体类型。允许的类型如下:
text
。纯文本。
blob
。对于除纯文本之外的所有媒体类型,请使用此类型并以原始字节形式上传数据。
MEDIA_CONTENT_N
:内容本身,以纯文本或原始字节的形式呈现。上下文数组的总内容必须少于 10 万个令牌。
PODCAST_TITLE
:播客的标题。此信息可供内部使用,您也可以选择向最终用户显示。
PODCAST_DESCRIPTION
:播客的说明。此信息可供内部使用,您也可以选择向最终用户显示。
命令和结果示例
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/my-project-123/locations/global/podcasts" \
-d '{
"podcastConfig": {
"focus": "Can you talk about how to find a job in Google?",
"length": "SHORT"
},
"contexts": [
{
"text": "Breaking into Google is a highly competitive endeavor, attracting millions of applicants globally due to its reputation as a top employer, its innovative work, and comprehensive perks. Success hinges on a multi-faceted approach, starting with meticulously tailored online applications that incorporate job description keywords for ATS and showcasing Googlyness—a blend of curiosity, collaborative spirit, and leadership potential. The rigorous, multi-stage interview process involves recruiter screens, behavioral interviews (often using the STAR method), and for technical roles, demanding coding challenges and system design questions that assess not just correct answers but also problem-solving thought processes and communication skills. Networking for referrals and informational interviews can significantly boost visibility, but ultimately, thorough preparation through mock interviews and platforms like LeetCode, combined with patience and resilience through the often lengthy process, are paramount for navigating this challenging but rewarding path."
},
{
"text": "Finding your way into a career at Google begins with their comprehensive careers website, a digital gateway brimming with opportunities. To embark on this journey, you first navigate the job board, using keywords like software engineer or product manager to pinpoint potential roles. To refine your search, utilize the array of filters available for location, experience level, degree, skills, and even specific Google organizations. You can even browse by team if you have a particular department in mind, like Engineering and Technology or Marketing and Communications. Once you discover a promising position, delve into its detailed description, paying close attention to the minimum qualifications – these are the foundational criteria against which your application will be assessed. Remember, Google seeks out leaders who can perform at the highest level, and while experience is valued, internships or graduate programs can be a great entry point for those earlier in their career. When you are ready to apply, you will need to create a Careers Profile, using your Google Account for seamless sign-in and communication. Crucially, tailor your resume for each specific role, highlighting relevant experiences and quantifying your achievements with concrete data. While a one-page resume is generally preferred, a two-page resume is acceptable for those with more extensive experience. Notably, cover letters are not typically required unless explicitly stated in the job description. Google encourages quality over quantity, so strategically apply for up to three jobs every 30 days, choosing roles that truly align with your skills and passions. Once you have submitted your applications, your Careers Profile becomes your tracking center, where you can monitor the status of each submission, from Draft to Submitted. If you do not hear back within eight weeks, the search continues, though Google recruiters may proactively reach out for other opportunities later. Remember, perseverance and a solid understanding of Google values, combined with a continuously refined skill set and a well-prepared resume, will greatly enhance your chances of securing a position at this innovative company."
}
],
"title": "Find a job at Google ",
"description": "This podcast is based on two plain text documents that describe various aspects of getting a job at Google."
}'
{
"name": "projects/123456/locations/global/operations/create-podcast-54321"
}
生成播客需要几分钟时间。
记下操作名称;您需要在第 4 步中使用该名称下载播客。在上面的示例中,操作名称为 projects/123456/locations/global/operations/create-podcast-54321
。
可选。轮询播客创建操作的状态。请参阅获取长时间运行的操作的详细信息。
操作完成后,运行以下 curl 命令下载播客:
curl -v \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://discoveryengine.googleapis.com/v1/OPERATION_NAME:download?alt=media" \
--output FILENAME.mp3 -L
替换以下内容:
OPERATION_NAME
:您在第 2 步中记下的操作的名称。
FILENAME
:播客的文件名。
此命令会将播客下载到本地目录中的 MP3 文件。
命令和结果示例
curl -v \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://discoveryengine.googleapis.com/v1/projects/123456/locations/global/operations/create-podcast-54321:download?alt=media" \
--output my-podcast.mp3 -L
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Host discoveryengine.googleapis.com:443 was resolved.
...
{ [42044 bytes data]
100 14.3M 100 14.3M 0 0 10.9M 0 0:00:01 0:00:01 --:--:-- 29.7M
* Connection #0 to host discoveryengine.googleapis.com left intact
合规性
播客 API 不符合客户管理的加密密钥 (CMEK for Gemini Enterprise) 的要求。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-10-19。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-10-19。"],[],[]]