如何获取一个会议的 transcripts

本文介绍了如何通过订阅消息和Bot Framework两种方法获取Microsoft Teams会议的transcripts。重点讲解了获取meetingId的难点,并提供了使用Graph API的具体代码示例。
摘要由CSDN通过智能技术生成

Teams 开发团队在过去半年里提供了很多的关于会议的 api,这让我们又有了很多的可以实现的功能和场景。今天我要介绍的是如何获取会议的 transcripts。

首先我们要知道的一个概念是:一个会议 meeting 可能有很多的 transcript,是一对多的关系,而不是一对一的关系。看到这里,对于熟悉 teams api 和 graph api 的读者可能已经在脑海里有了一个这样的api的:GET meetings/{meetingId}/transcripts,恭喜你,你已经对微软的 api 设计有了非常好的 sense。

我们来看一下官方的 api 定义:

  • 获取transcript列表
GET /me/onlineMeetings/{meetingId}/transcripts
GET /users/{userId}/onlineMeetings/{meetingId}/transcripts
  • 获取某一个具体的 transcript 的内容
GET me/onlineMeetings/{meetingId}/transcripts/{transcriptId}/content
GET users/{userId}/onlineMeetings/{meetingId}/transcripts/{transcriptId}/content

看到这里大家是不是已经开始准备撸起袖子开干了?不要急,这里面最困难的是如何获取 meetingId,说实话,我觉得微软已经提供一些更好的方法让我们获取 meeting id,但现实是到写这篇文章开始,还没有特别好的方法,官方提供的有两种方法:

方法一:订阅消息

以下是一个基于 Python 和 Google Cloud Speech-to-Text API 的简单英语听写软件的代码示例: ```python import tkinter as tk import pyaudio import wave import io import os from google.cloud import speech_v1p1beta1 as speech from google.cloud.speech_v1p1beta1 import enums # 设置 Google Cloud 服务账号文件路径 os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '/path/to/your/credentials.json' # 初始化 Google Cloud 语音识别客户端 client = speech.SpeechClient() # 定义录音参数 CHUNK = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 16000 RECORD_SECONDS = 5 WAVE_OUTPUT_FILENAME = "output.wav" class EnglishDictationApp: def __init__(self, master): self.master = master master.title("English Dictation App") # 创建录音和听写按钮 self.record_button = tk.Button(master, text="Record", command=self.record) self.record_button.pack() self.transcribe_button = tk.Button(master, text="Transcribe", command=self.transcribe, state=tk.DISABLED) self.transcribe_button.pack() # 创建输入框和答案框 self.input_text = tk.Text(master, height=5, width=50) self.input_text.pack() self.answer_text = tk.Text(master, height=5, width=50, state=tk.DISABLED) self.answer_text.pack() def record(self): # 创建 PyAudio 对象 audio = pyaudio.PyAudio() # 打开音频流 stream = audio.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK) print("Recording...") frames = [] # 录制音频 for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): data = stream.read(CHUNK) frames.append(data) print("Recording finished.") # 停止音频流 stream.stop_stream() stream.close() audio.terminate() # 保存音频文件 wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb') wf.setnchannels(CHANNELS) wf.setsampwidth(audio.get_sample_size(FORMAT)) wf.setframerate(RATE) wf.writeframes(b''.join(frames)) wf.close() # 激活听写按钮 self.transcribe_button.config(state=tk.NORMAL) def transcribe(self): # 读取音频文件 with io.open(WAVE_OUTPUT_FILENAME, 'rb') as audio_file: content = audio_file.read() # 创建语音识别请求对象 audio = speech.types.RecognitionAudio(content=content) config = speech.types.RecognitionConfig( encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=RATE, language_code='en-US') # 发送语音识别请求 response = client.recognize(config, audio) # 获取识别结果 transcripts = [result.alternatives[0].transcript for result in response.results] # 显示识别结果 self.answer_text.config(state=tk.NORMAL) self.answer_text.delete(1.0, tk.END) self.answer_text.insert(tk.END, '\n'.join(transcripts)) self.answer_text.config(state=tk.DISABLED) # 启动应用 root = tk.Tk() app = EnglishDictationApp(root) root.mainloop() ``` 这个代码示例使用 PyAudio 库录制音频,使用 Google Cloud Speech-to-Text API 进行语音识别,使用 tkinter 库构建了一个简单的用户界面。当用户点击 "Record" 按钮时,程序会开始录制音频;当用户点击 "Transcribe" 按钮时,程序会使用 Google Cloud Speech-to-Text API 对录制的音频进行语音识别,并将识别结果显示在用户界面上。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值