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
| class AdvancedVoiceFeatures:
def __init__(self):
self.emotion_map = {
"happy": {"pitch": 1.1, "speed": 1.05, "energy": 1.2},
"sad": {"pitch": 0.9, "speed": 0.95, "energy": 0.8},
"excited": {"pitch": 1.2, "speed": 1.15, "energy": 1.3},
"calm": {"pitch": 1.0, "speed": 0.9, "energy": 0.9},
"angry": {"pitch": 1.05, "speed": 1.1, "energy": 1.25}
}
def apply_emotion(self, text: str, emotion: str):
"""应用情感参数"""
params = self.emotion_map.get(emotion, {})
return {
"type": "response.create",
"response": {
"modalities": ["audio"],
"instructions": f"Speak with {emotion} emotion",
"voice_settings": params,
"input": [{
"type": "input_text",
"text": text
}]
}
}
def function_calling_with_voice(self, function_name: str, parameters: dict):
"""语音函数调用"""
return {
"type": "conversation.item.create",
"item": {
"type": "function_call",
"name": function_name,
"arguments": json.dumps(parameters),
"voice_response": True # 启用语音响应
}
}
|