在本教程中,您将构建一个自动生成会议纪要的应用。该应用会转写会议录音,总结讨论内容,提取要点和待办事项,分析讨论中的情感倾向,并将结果保存为 Word 文档。
开始之前,您需要熟悉一种受支持的编程语言,并准备好 OpenAI API 密钥。您可以使用示例音频片段快速测试,也可以使用自己的录音,录音文件大小不能超过 25 MB。
请安装 OpenAI SDK,并为您使用的语言安装相应的 DOCX 库:
将下载的文件命名为 meeting.wav,保存到运行示例的目录中,或者将示例中的 meeting.wav 替换为您自己的录音文件路径。下载的音频片段可用于验证整个流程是否正常运行。要生成有用的摘要和待办事项,请使用不超过 25 MB 的真实会议录音。
定义一个辅助函数,用于打开录音文件并将文件内容发送给 gpt-transcribe:
1
2
3
4
5
6
7
8
9
10
11
12
13
14import fs from "node:fs";
import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "docx";
import OpenAI from "openai";
const openai = new OpenAI();
async function transcribeAudio(audioFilePath: fs.PathLike) {
const transcription = await openai.audio.transcriptions.create({
file: fs.createReadStream(audioFilePath),
model: "gpt-transcribe",
});
return transcription.text;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15from pathlib import Path
from docx import Document
from openai import OpenAI
client = OpenAI()
def transcribe_audio(audio_file_path: str | Path) -> str:
with Path(audio_file_path).open("rb") as audio_file:
transcription = client.audio.transcriptions.create(
file=audio_file,
model="gpt-transcribe",
)
return transcription.text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37package main
import (
"context"
"fmt"
"os"
"strings"
"github.com/gomutex/godocx"
"github.com/openai/openai-go/v3"
)
type meetingMinutes struct {
AbstractSummary string
KeyPoints string
ActionItems string
Sentiment string
}
var client = openai.NewClient()
func transcribeAudio(ctx context.Context, audioFilePath string) (string, error) {
audioFile, err := os.Open(audioFilePath)
if err != nil {
return "", err
}
defer audioFile.Close()
transcription, err := client.Audio.Transcriptions.New(ctx, openai.AudioTranscriptionNewParams{
File: audioFile,
Model: "gpt-transcribe",
})
if err != nil {
return "", err
}
return transcription.Text, nil
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.audio.transcriptions.TranscriptionCreateParams;
import com.openai.models.chat.completions.ChatCompletionCreateParams;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFStyle;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STStyleType;
public final class TutorialMeetingMinutesExample {
private TutorialMeetingMinutesExample() {}
record MeetingMinutes(
String abstractSummary, String keyPoints, String actionItems, String sentiment) {}
private static final class ClientHolder {
private static final OpenAIClient INSTANCE = OpenAIOkHttpClient.fromEnv();
}
private static OpenAIClient client() {
return ClientHolder.INSTANCE;
}
static String transcribeAudio(Path audioFilePath) {
var transcription =
client()
.audio()
.transcriptions()
.create(
TranscriptionCreateParams.builder()
.file(audioFilePath)
.model("gpt-transcribe")
.build());
return transcription.asTranscription().text();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17using System.IO.Compression;
using System.Text.Json;
using System.Xml.Linq;
using OpenAI.Audio;
using OpenAI.Chat;
internal static class MeetingMinutes
{
private static readonly string Key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
private static readonly AudioClient Audio = new("gpt-transcribe", Key);
private static readonly ChatClient Chat = new("gpt-5.5", Key);
private static async Task<string> TranscribeAudioAsync(string path)
{
AudioTranscription transcription = await Audio.TranscribeAudioAsync(path);
return transcription.Text;
}
1
2
3
4
5
6
7
8
9
10
11
12
13require "caracal"
require "openai"
require "pathname"
client = OpenAI::Client.new
def transcribe_audio(client, audio_file_path)
transcription = client.audio.transcriptions.create(
file: Pathname(audio_file_path),
model: "gpt-transcribe"
)
transcription.text
end
该函数接收本地音频文件的路径,使用相应编程语言的标准文件 API 打开文件,然后将文件内容传给转写模型。转写端点需要音频的字节数据,仅提供本地路径或远程 URL 无法完成转写。如果服务器将录音存储在其他位置,请先下载录音并将其放入请求中,或以流式方式将录音写入请求,再发起转写。
通过 Chat Completions API 将转写文本发送给 GPT 模型。本教程演示如何在现有集成中使用 Chat Completions,这种方式仍受支持。对于新项目,请使用 Responses API,并先选用 gpt-6.2-astra。以下代码示例使用经过测试的模型来生成摘要、提取要点和待办事项,并分析情感倾向。
本教程为每项任务单独调用一次模型。您可以将各项任务的指令合并到一个请求中,以减少调用次数。使用单独的提示词则更方便分别调整各项任务的输出。
定义一个共用的辅助函数,将转写文本和针对具体任务的指令发送给模型:
1
2
3
4
5
6
7
8
9
10async function complete(transcription: string, instructions: string) {
const response = await openai.chat.completions.create({
model: "gpt-5.5",
messages: [
{ role: "system", content: instructions },
{ role: "user", content: transcription },
],
});
return response.choices[0].message.content ?? "";
}
1
2
3
4
5
6
7
8
9def complete(transcription: str, instructions: str) -> str:
response = client.chat.completions.create(
model="gpt-5.5",
messages=[
{"role": "system", "content": instructions},
{"role": "user", "content": transcription},
],
)
return response.choices[0].message.content or ""
1
2
3
4
5
6
7
8
9
10
11
12
13func complete(ctx context.Context, transcription, instructions string) (string, error) {
response, err := client.Chat.Completions.New(ctx, openai.ChatCompletionNewParams{
Model: "gpt-5.5",
Messages: []openai.ChatCompletionMessageParamUnion{
openai.SystemMessage(instructions),
openai.UserMessage(transcription),
},
})
if err != nil {
return "", err
}
return response.Choices[0].Message.Content, nil
}
1
2
3
4
5
6
7
8
9
10
11
12
13private static String complete(String transcription, String instructions) {
var response =
client()
.chat()
.completions()
.create(
ChatCompletionCreateParams.builder()
.model("gpt-5.5")
.addSystemMessage(instructions)
.addUserMessage(transcription)
.build());
return response.choices().get(0).message().content().orElse("");
}
1
2
3
4
5private static async Task<string> CompleteAsync(string transcription, string instructions)
{
ChatCompletion completion = await Chat.CompleteChatAsync([new SystemChatMessage(instructions), new UserChatMessage(transcription)]);
return completion.Content[0].Text;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16def complete(client, transcription, instructions)
response = client.chat.completions.create(
model: "gpt-5.5",
messages: [
{
role: :system,
content: instructions
},
{
role: :user,
content: transcription
}
]
)
response.choices.first.message.content || ""
end
定义一个负责协调各项任务的辅助函数,返回会议纪要的四个部分:
1
2
3
4
5
6
7
8async function buildMeetingMinutes(transcription: string) {
return {
"Abstract summary": await extractAbstractSummary(transcription),
"Key points": await extractKeyPoints(transcription),
"Action items": await extractActionItems(transcription),
Sentiment: await analyzeSentiment(transcription),
};
}
1
2
3
4
5
6
7def meeting_minutes(transcription: str) -> dict[str, str]:
return {
"Abstract summary": abstract_summary_extraction(transcription),
"Key points": key_points_extraction(transcription),
"Action items": action_item_extraction(transcription),
"Sentiment": sentiment_analysis(transcription),
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19func buildMeetingMinutes(ctx context.Context, transcription string) (meetingMinutes, error) {
summary, err := extractAbstractSummary(ctx, transcription)
if err != nil {
return meetingMinutes{}, err
}
keyPoints, err := extractKeyPoints(ctx, transcription)
if err != nil {
return meetingMinutes{}, err
}
actionItems, err := extractActionItems(ctx, transcription)
if err != nil {
return meetingMinutes{}, err
}
sentiment, err := analyzeSentiment(ctx, transcription)
if err != nil {
return meetingMinutes{}, err
}
return meetingMinutes{summary, keyPoints, actionItems, sentiment}, nil
}
1
2
3
4
5
6
7static MeetingMinutes buildMeetingMinutes(String transcription) {
return new MeetingMinutes(
extractAbstractSummary(transcription),
extractKeyPoints(transcription),
extractActionItems(transcription),
analyzeSentiment(transcription));
}
1
2
3
4
5
6
7private static async Task<Dictionary<string, string>> BuildMeetingMinutesAsync(string transcription) => new()
{
["Abstract summary"] = await ExtractAbstractSummaryAsync(transcription),
["Key points"] = await ExtractKeyPointsAsync(transcription),
["Action items"] = await ExtractActionItemsAsync(transcription),
["Sentiment"] = await AnalyzeSentimentAsync(transcription),
};
1
2
3
4
5
6
7
8def build_meeting_minutes(client, transcription)
{
"Abstract summary" => extract_abstract_summary(client, transcription),
"Key points" => extract_key_points(client, transcription),
"Action items" => extract_action_items(client, transcription),
"Sentiment" => analyze_sentiment(client, transcription)
}
end
该函数将转写文本传给四个辅助函数,分别用于生成摘要、提取要点、提取待办事项和分析情感倾向。如果应用需要进行其他分析,您可以再添加一个辅助函数,并在输出中增加相应的部分。
各个函数的具体作用如下。
摘要函数要求模型用一段简洁的文字概括讨论,保留重要决策及相关背景,略去偏离主题的内容。系统消息决定模型如何生成摘要。如需了解更多调整输出的方法,请参阅提示词工程指南。
1
2
3
4
5
6async function extractAbstractSummary(transcription: string) {
return complete(
transcription,
"Summarize the meeting transcript in one concise paragraph. Keep the most important decisions and context, and omit tangents."
);
}
1
2
3
4
5
6def abstract_summary_extraction(transcription: str) -> str:
return complete(
transcription,
"Summarize the meeting transcript in one concise paragraph. "
"Keep the most important decisions and context, and omit tangents.",
)
1
2
3func extractAbstractSummary(ctx context.Context, transcription string) (string, error) {
return complete(ctx, transcription, "Summarize the meeting transcript in one concise paragraph. Keep the most important decisions and context, and omit tangents.")
}
1
2
3
4
5
6static String extractAbstractSummary(String transcription) {
return complete(
transcription,
"Summarize the meeting transcript in one concise paragraph. "
+ "Keep the most important decisions and context, and omit tangents.");
}
1
2private static Task<string> ExtractAbstractSummaryAsync(string transcription) => CompleteAsync(transcription,
"Summarize the meeting transcript in one concise paragraph. Keep the most important decisions and context, and omit tangents.");
1
2
3
4
5
6
7def extract_abstract_summary(client, transcription)
complete(
client,
transcription,
"Summarize the meeting transcript in one concise paragraph. Keep the most important decisions and context, and omit tangents."
)
end
要点提取函数列出会议中讨论的重要观点、发现和议题。如果项目或公司的背景信息有助于模型判断哪些内容对读者最重要,请将相关信息加入系统消息。
1
2
3
4
5
6async function extractKeyPoints(transcription: string) {
return complete(
transcription,
"List the most important ideas, findings, and topics from the meeting. Use concise bullet points."
);
}
1
2
3
4
5
6def key_points_extraction(transcription: str) -> str:
return complete(
transcription,
"List the most important ideas, findings, and topics from the meeting. "
"Use concise bullet points.",
)
1
2
3func extractKeyPoints(ctx context.Context, transcription string) (string, error) {
return complete(ctx, transcription, "List the most important ideas, findings, and topics from the meeting. Use concise bullet points.")
}
1
2
3
4
5
6static String extractKeyPoints(String transcription) {
return complete(
transcription,
"List the most important ideas, findings, and topics from the meeting. "
+ "Use concise bullet points.");
}
1
2private static Task<string> ExtractKeyPointsAsync(string transcription) => CompleteAsync(transcription,
"List the most important ideas, findings, and topics from the meeting. Use concise bullet points.");
1
2
3
4
5
6
7def extract_key_points(client, transcription)
complete(
client,
transcription,
"List the most important ideas, findings, and topics from the meeting. Use concise bullet points."
)
end
待办事项提取函数识别任务和需要跟进的事项。如果转写文本中提到了负责人和截止日期,函数也会一并提取。要在其他系统中创建和分配任务,请在这一步接入函数调用。
1
2
3
4
5
6async function extractActionItems(transcription: string) {
return complete(
transcription,
"List every task or follow-up agreed to in the meeting. Include the owner and deadline when the transcript provides them."
);
}
1
2
3
4
5
6def action_item_extraction(transcription: str) -> str:
return complete(
transcription,
"List every task or follow-up agreed to in the meeting. "
"Include the owner and deadline when the transcript provides them.",
)
1
2
3func extractActionItems(ctx context.Context, transcription string) (string, error) {
return complete(ctx, transcription, "List every task or follow-up agreed to in the meeting. Include the owner and deadline when the transcript provides them.")
}
1
2
3
4
5
6static String extractActionItems(String transcription) {
return complete(
transcription,
"List every task or follow-up agreed to in the meeting. "
+ "Include the owner and deadline when the transcript provides them.");
}
1
2private static Task<string> ExtractActionItemsAsync(string transcription) => CompleteAsync(transcription,
"List every task or follow-up agreed to in the meeting. Include the owner and deadline when the transcript provides them.");
1
2
3
4
5
6
7def extract_action_items(client, transcription)
complete(
client,
transcription,
"List every task or follow-up agreed to in the meeting. Include the owner and deadline when the transcript provides them."
)
end
情感分析函数将讨论的整体情感倾向归为积极、消极或中性,并说明判断依据。对于较简单的任务,您可以尝试 gpt-6.1-terra,看看它能否以更低的成本和更短的延迟达到您的质量目标。
1
2
3
4
5
6async function analyzeSentiment(transcription: string) {
return complete(
transcription,
"Describe the meeting's overall sentiment as positive, negative, or neutral, and briefly explain the assessment."
);
}
1
2
3
4
5
6def sentiment_analysis(transcription: str) -> str:
return complete(
transcription,
"Describe the meeting's overall sentiment as positive, negative, or "
"neutral, and briefly explain the assessment.",
)
1
2
3func analyzeSentiment(ctx context.Context, transcription string) (string, error) {
return complete(ctx, transcription, "Describe the meeting's overall sentiment as positive, negative, or neutral, and briefly explain the assessment.")
}
1
2
3
4
5
6static String analyzeSentiment(String transcription) {
return complete(
transcription,
"Describe the meeting's overall sentiment as positive, negative, or neutral, "
+ "and briefly explain the assessment.");
}
1
2private static Task<string> AnalyzeSentimentAsync(string transcription) => CompleteAsync(transcription,
"Describe the meeting's overall sentiment as positive, negative, or neutral, and briefly explain the assessment.");
1
2
3
4
5
6
7def analyze_sentiment(client, transcription)
complete(
client,
transcription,
"Describe the meeting's overall sentiment as positive, negative, or neutral, and briefly explain the assessment."
)
end
将会议纪要保存为便于阅读和分发的格式。Microsoft Word 是这类报告的常见选择。示例使用了适合各编程语言的 DOCX 库。在端到端应用中,您也可以通过电子邮件发送结果,或将结果写入其他系统。
定义一个辅助函数,将各部分的结果写入 Word 文档:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15async function saveAsDocx(minutes: Record<string, string>, filename: string) {
const children = Object.entries(minutes).flatMap(([heading, content]) => [
new Paragraph({ text: heading, heading: HeadingLevel.HEADING_1 }),
new Paragraph({
children: content
.split(/\r\n?|\n/)
.flatMap((line, index) => [
...(index > 0 ? [new TextRun({ break: 1 })] : []),
new TextRun(line),
]),
}),
]);
const document = new Document({ sections: [{ children }] });
await fs.promises.writeFile(filename, await Packer.toBuffer(document));
}
1
2
3
4
5
6def save_as_docx(minutes: dict[str, str], filename: Path) -> None:
document = Document()
for heading, content in minutes.items():
document.add_heading(heading, level=1)
document.add_paragraph(content)
document.save(filename)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18func saveAsDocx(minutes meetingMinutes, filename string) error {
document, err := godocx.NewDocument()
if err != nil {
return err
}
for _, section := range []struct{ heading, content string }{
{"Abstract summary", minutes.AbstractSummary},
{"Key points", minutes.KeyPoints},
{"Action items", minutes.ActionItems},
{"Sentiment", minutes.Sentiment},
} {
document.AddHeading(section.heading, 1)
for _, line := range strings.Split(strings.ReplaceAll(section.content, "\r\n", "\n"), "\n") {
document.AddParagraph(line)
}
}
return document.SaveTo(filename)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35static void saveAsDocx(MeetingMinutes minutes, Path filename) throws IOException {
try (var document = new XWPFDocument();
OutputStream output = Files.newOutputStream(filename)) {
addHeadingStyle(document);
addSection(document, "Abstract summary", minutes.abstractSummary());
addSection(document, "Key points", minutes.keyPoints());
addSection(document, "Action items", minutes.actionItems());
addSection(document, "Sentiment", minutes.sentiment());
document.write(output);
}
}
private static void addHeadingStyle(XWPFDocument document) {
var headingStyle = CTStyle.Factory.newInstance();
headingStyle.setStyleId("Heading1");
headingStyle.addNewName().setVal("Heading 1");
headingStyle.setType(STStyleType.PARAGRAPH);
headingStyle.addNewPPr().addNewOutlineLvl().setVal(BigInteger.ZERO);
document.createStyles().addStyle(new XWPFStyle(headingStyle));
}
private static void addSection(XWPFDocument document, String heading, String content) {
var headingParagraph = document.createParagraph();
headingParagraph.setStyle("Heading1");
var headingRun = headingParagraph.createRun();
headingRun.setBold(true);
headingRun.setFontSize(16);
headingRun.setText(heading);
var contentRun = document.createParagraph().createRun();
String[] lines = content.split("\\R", -1);
for (int index = 0; index < lines.length; index += 1) {
if (index > 0) contentRun.addBreak();
contentRun.setText(lines[index]);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23private static void SaveAsDocx(Dictionary<string, string> minutes, string path)
{
XNamespace word = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
XElement body = new(word + "body");
foreach ((string heading, string content) in minutes)
{
body.Add(new XElement(word + "p", new XElement(word + "r",
new XElement(word + "rPr", new XElement(word + "b")), new XElement(word + "t", heading))));
foreach (string line in content.Replace("\r\n", "\n", StringComparison.Ordinal).Split('\n'))
body.Add(new XElement(word + "p", new XElement(word + "r", new XElement(word + "t", line))));
}
using FileStream file = File.Create(path);
using ZipArchive archive = new(file, ZipArchiveMode.Create);
WriteEntry(archive, "[Content_Types].xml", """<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/></Types>""");
WriteEntry(archive, "_rels/.rels", """<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/></Relationships>""");
WriteEntry(archive, "word/document.xml", new XDocument(new XElement(word + "document", body)).ToString());
}
private static void WriteEntry(ZipArchive archive, string name, string content)
{
using StreamWriter writer = new(archive.CreateEntry(name).Open());
writer.Write(content);
}
1
2
3
4
5
6
7
8def save_as_docx(minutes, filename)
Caracal::Document.save(filename) do |document|
minutes.each do |heading, content|
document.h1(heading)
content.split(/\r\n?|\n/, -1).each { |line| document.p(line) }
end
end
end
该函数接收已生成的各部分内容和输出文件名,为每个部分添加标题和正文段落,然后将文档保存到当前工作目录。
最后,将上述步骤串联起来,从音频文件生成会议纪要:
1
2
3
4const transcription = await transcribeAudio("meeting.wav");
const minutes = await buildMeetingMinutes(transcription);
console.log(minutes);
await saveAsDocx(minutes, "meeting_minutes.docx");
1
2
3
4
5audio_file_path = Path("meeting.wav")
transcription = transcribe_audio(audio_file_path)
minutes = meeting_minutes(transcription)
print(minutes)
save_as_docx(minutes, Path("meeting_minutes.docx"))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15func main() {
ctx := context.Background()
transcription, err := transcribeAudio(ctx, "meeting.wav")
if err != nil {
panic(err)
}
minutes, err := buildMeetingMinutes(ctx, transcription)
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", minutes)
if err := saveAsDocx(minutes, "meeting_minutes.docx"); err != nil {
panic(err)
}
}
1
2
3
4
5
6
7public static void main(String[] args) throws IOException {
String transcription = transcribeAudio(Path.of("meeting.wav"));
MeetingMinutes minutes = buildMeetingMinutes(transcription);
System.out.println(minutes);
saveAsDocx(minutes, Path.of("meeting_minutes.docx"));
}
}
1
2
3
4
5
6
7
8internal static async Task RunAsync()
{
string transcription = await TranscribeAudioAsync("meeting.wav");
Dictionary<string, string> minutes = await BuildMeetingMinutesAsync(transcription);
Console.WriteLine(JsonSerializer.Serialize(minutes));
SaveAsDocx(minutes, "meeting_minutes.docx");
}
}
1
2
3
4transcription = transcribe_audio(client, "meeting.wav")
minutes = build_meeting_minutes(client, transcription)
puts minutes
save_as_docx(minutes, "meeting_minutes.docx")
这段代码在进程的工作目录中查找 meeting.wav,生成并打印会议纪要,然后将纪要保存为 meeting_minutes.docx。
有了这个基本的会议纪要生成流程,您可以运用提示词工程来优化提示词,也可以通过函数调用构建端到端系统。