🎨 OpenAI 多模态开发入门:从Sora文生视频到Whisper语音识别的全面指南
一、本章概览
第18章《OpenAI 多模态开发入门》是课程中探索AI多模态能力最前沿的章节——全面覆盖OpenAI提供的五大多模态能力:文生视频(Sora)、文生图(DALL·E 3)、图生文(GPT-4V)、文生音(TTS)、音生文(Whisper),并通过丰富的代码实战示例,带你一站式掌握多模态AI开发。
核心内容速览:
|
|
|
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
二、OpenAI 多模态能力总览
OpenAI 目前提供的五大多模态能力:
OpenAI 多模态能力
├── 🎬 文生视频(Text-to-Video)── Sora
├── 🖼️ 文生图像(Text-to-Image) ── DALL·E 系列
├── 👁️ 图像理解(Image Understanding)── GPT-4 with Vision (GPT-4V)
├── 🎙️ 语音识别(Speech-to-Text)── Whisper
└── 🎵 文字配音(Text-to-Speech)── TTS
多模态开发入门的四个方向:
|
|
|
|
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
三、文生视频:Sora
3.1 基本介绍
★Sora is an AI model that can create realistic and imaginative scenes from text instructions.
Sora是OpenAI推出的文生视频AI模型,能够根据文字指令创建逼真且富有想象力的场景。
3.2 Prompt 示例
示例1:东京街头时尚女郎
★A stylish woman walks down a Tokyo street filled with warm glowing neon and animated city signage. She wears a black leather jacket, a long red dress, and black boots, and carries a black purse. She wears sunglasses and red lipstick. She walks confidently and casually. The street is damp and reflective, creating a mirror effect of the colorful lights. Many pedestrians walk about.
示例2:山间复古SUV
★The camera follows behind a white vintage SUV with a black roof rack as it speeds up a steep dirt road surrounded by pine trees on a steep mountain slope, dust kicks up from it's tires, the sunlight shines on the SUV as it speeds along the dirt road, casting a warm glow over the scene...
3.3 申请与使用
★⚠️ 当前状态:Sora现在可供红队成员(Red Team) 使用,以评估危害或风险的关键领域。同时,OpenAI还授予一些视觉艺术家、设计师和电影制作人访问权限,以获取关于如何推进该模型对创意专业人士最有帮助的反馈。
★目前尚未对公众开放使用。
四、文生图:DALL·E 3
4.1 发展历程
|
|
|
|
|---|---|---|
| DALL·E |
|
|
| DALL·E 2 |
|
|
| DALL·E 3 |
|
|
4.2 图像生成 API 参数
from openai import OpenAI
client = OpenAI()
response = client.images.generate(
model="dall-e-3",
prompt="a white siamese cat",
size="1024x1024",
quality="standard",
n=1,
style="vivid"
)
print(response.data[0].url)
|
|
|
|
|
|---|---|---|---|
| model |
|
dall-e-2
dall-e-3
|
dall-e-2 |
| prompt |
|
|
|
| n |
|
|
|
| size |
|
256x256/512x512/1024x1024DALL·E-3: 1024x1024/1792x1024/1024x1792
|
1024x1024 |
| quality |
|
standard
hd
|
standard |
| style |
|
vivid
natural(自然)
|
vivid |
| response_format |
|
url
b64_json
|
url |
4.3 风格对比
|
|
|
|
|---|---|---|
| vivid
|
|
|
| natural
|
|
|
★💡 在 DALL·E 3 中,即使相同的 Prompt,使用 vivid 和 natural 风格会得到截然不同的视觉效果。关于DALL·E 3模型更新的更多内容,可参考OpenAI Cookbook。
五、图生文:GPT-4V(GPT-4 with Vision)
5.1 使用 ChatAPI 识别图像
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4-turbo",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "介绍下这幅图?"},
{
"type": "image_url",
"image_url": {
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/..."
}
}
]
}
],
max_tokens=300,
)
print(response.choices[0])
★示例输出:模型会返回对图像内容的自然语言描述——如描述一条木板路、绿色草地、蓝天白云等自然景观,并指出画面宁静平和,适合散步和放松。
5.2 GPT-4V 图表解读
通过 Assistants API 生成GDP 40年对比曲线图,GPT-4V能够识别出图中:
-
四条折线分别代表美国、中国、日本、德国 -
1980-2020年四国的GDP增长趋势对比 -
颜色与国家的对应关系
★⚠️ 注意:目前在 Assistants API 中使用 GPT-4 时还不支持图像输入。
六、文生音:OpenAI TTS
6.1 服务说明
文字配音 API 基于 TTS(Text-to-Speech) 模型,可用于:
-
📖 朗读书面博客文章 -
🌍 用多种语言制作口语音频 -
📡 使用流媒体实时提供音频输出
6.2 6种配音
|
|
|
|---|---|
| alloy |
|
| echo
|
|
| fable |
|
| onyx
|
|
| nova |
|
| shimmer |
|
6.3 输出格式
|
|
|
|
|---|---|---|
| mp3 |
|
|
| opus |
|
|
| aac |
|
|
| flac |
|
|
| wav |
|
|
| pcm |
|
|
6.4 文字配音 API 参数
|
|
|
|
|---|---|---|
| model |
|
tts-1
tts-1-hd
|
| input |
|
最大4096字符 |
| voice |
|
alloy
echo/fable/onyx/nova/shimmer
|
| response_format |
|
mp3
opus/aac/flac/wav/pcm,默认mp3
|
| speed |
|
0.25 到 4.0
|
6.5 实战示例:给李云龙台词配音
from openai import OpenAI
client = OpenAI()
speech_file_path = "./audio/liyunlong.mp3"
# 官方示例的用法会触发Deprecated警告!已替换为最佳实践
with client.audio.speech.with_streaming_response.create(
model="tts-1",
voice="echo",
input="二营长!你他娘的意大利炮呢?给我拉来!"
) as response:
response.stream_to_file(speech_file_path)
6.6 更多实战示例
|
|
|
|
|---|---|---|
|
|
quewang.mp3 |
|
|
|
boyin.mp3 |
|
|
|
|
|
七、音生文:Whisper
7.1 模型介绍
|
|
|
|---|---|
| 参数量 | 1.54B |
| 训练数据 | 68万小时
|
| 模型大小 |
|
| 论文 |
|
| License |
|
| 文件限制 | 25MB |
| 支持格式 |
|
★Whisper是一个用于自动语音识别(ASR)和语音翻译的预训练模型,由 Alec Radford 等人在论文《Robust Speech Recognition via Large-Scale Weak Supervision》中提出(OpenAI)。
Whisper模型表现出强大的泛化能力——无需微调即可适应许多数据集和领域。
与Whisper large模型相比,large-v2模型训练了2.5倍以上的epochs,并添加了正则化以提高性能。
HuggingFace 线上体验:https://huggingface.co/openai/whisper-large-v2
7.2 两大API服务
语音转录(Transcriptions)
将音频转录为音频所使用的任何语言。
请求参数:
|
|
|
|
|---|---|---|
| file |
|
|
| model |
|
whisper-1
|
| language
|
|
|
| prompt
|
|
|
| response_format
|
|
json
text/srt/verbose_json/vtt,默认json
|
| temperature
|
|
|
|
|
|
word
segment(需verbose_json)
|
返回值示例(Verbose Transcription Object):
{
"task": "transcribe",
"language": "chinese",
"duration": 15.95,
"text": "完整转录文本",
"segments": [
{
"id": 0,
"seek": 0,
"start": 0.0,
"end": 4.0,
"text": "文本段落",
"tokens": [...],
"temperature": 0.0,
"avg_logprob": -0.98,
"compression_ratio": 2.06,
"no_speech_prob": 0.02
}
]
}
语音翻译(Translations)
将音频翻译并转录为英语。
请求参数:
|
|
|
|---|---|
| file |
|
| model | whisper-1 |
| prompt
|
|
| response_format
|
|
| temperature
|
|
★返回值:
translated_text(翻译后的英文文本)
八、综合实战:Whisper + TTS 跨语言语音转换
8.1 李云龙英文版
步骤1:Whisper 音生文(转录中文台词)
步骤2:Whisper 翻译 API(中文→英文翻译)
步骤3:TTS 配音(用 onyx 配音合成英文语音)
8.2 郭德纲相声英文版
步骤1:读取音频文件 gdg.mp3
步骤2:Whisper 翻译为英文
步骤3:TTS 用 onyx 配音 → 输出 gdg_en.mp3
九、OpenAI 多模态能力全景总结
|
|
|
|
|
|
|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
📌 本章核心要点总结
|
|
|
|
|---|---|---|
|
|
五大多模态能力 |
|
|
|
Sora文生视频 |
|
|
|
DALL·E 3三大增强参数 |
|
|
|
GPT-4V图像识别 |
|
|
|
TTS六种配音 |
|
|
|
TTS输出六种格式 |
|
|
|
Whisper训练数据 |
|
|
|
Whisper两大API |
|
|
|
综合实战 |
|
|
|
多模态开发入门四方向 |
|
★📚 本课程系列文章持续更新中,欢迎关注!🚀
至此,AI大模型应用开发实战营共计18章的核心知识点已全部整理完成!🎉

