会议助手——实时语音识别,翻译及GPT Answer

由于时效问题,该文某些代码、技术可能已经过期,请注意!!!本文最后更新于:3 个月前

大模型提升会议效率

语音识别组件: react-speech-kit, 项目地址:https://github.com/MikeyParton/react-speech-kit
翻译api参考: https://blog.zhuanjie.ltd/2023/10/05/api-with-cloudflare/

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
import azure.cognitiveservices.speech as speechsdk
from sparkdesk_api.core import SparkAPI
# 默认api接口版本为3.1,配置其他版本需要指定Version参数(2.1或者1.1)

sparkAPI = SparkAPI(
app_id='9829fafe',
api_secret='******',
api_key='******',
# version=3.1
)

from zhipuai import ZhipuAI
client = ZhipuAI(api_key="****") # 请填写您自己的APIKey

def chatglm(message):
response = client.chat.completions.create(
model="glm-4", # 填写需要调用的模型名称
messages=[
{"role": "user", "content": message},
],
stream=False,
)
print(response.choices[0].message.content)

def chatSpark(message):
ai_reply = sparkAPI.chat(message)
print(ai_reply)

speech_key, service_region = "f739afd4250b410aaedca2967c1a78f1", "eastus"
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region,speech_recognition_language="zh-cn")

# Creates a recognizer with the given settings
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)

# print("Say something...")

# result = speech_recognizer.recognize_once()

# if result.reason == speechsdk.ResultReason.RecognizedSpeech:
# print("Recognized: {}".format(result.text))
# elif result.reason == speechsdk.ResultReason.NoMatch:
# print("No speech could be recognized: {}".format(result.no_match_details))
# elif result.reason == speechsdk.ResultReason.Canceled:
# cancellation_details = result.cancellation_details
# print("Speech Recognition canceled: {}".format(cancellation_details.reason))
# if cancellation_details.reason == speechsdk.CancellationReason.Error:
# print("Error details: {}".format(cancellation_details.error_details))


def chatSpark(message):
ai_reply = sparkAPI.chat(message)
print(ai_reply)


text_ls = []


def recognized_callback(evt):
if evt.result.text:
print("Recognized: {}".format(evt.result.text))
text_ls.append(evt.result.text)
chatSpark(evt.result.text)
if "退出" in evt.result.text.lower():
print('byebye')
os._exit(0)
# speech_recognizer.stop_continuous_recognition()



def cancelled_callback(evt):
print("Cancelled: {}".format(evt.result.error_details))

speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)
speech_recognizer.recognized.connect(recognized_callback)
speech_recognizer.session_stopped.connect(cancelled_callback)

print("Say something...")
speech_recognizer.start_continuous_recognition()



while True:
pass