smartpi 1.1.2__py3-none-any.whl → 1.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- smartpi/__init__.pyc +0 -0
- smartpi/_gui.pyc +0 -0
- smartpi/ai_asr.pyc +0 -0
- smartpi/ai_llm.pyc +0 -0
- smartpi/ai_tts.pyc +0 -0
- smartpi/ai_vad.pyc +0 -0
- smartpi/audio.pyc +0 -0
- smartpi/base_driver.pyc +0 -0
- smartpi/camera.pyc +0 -0
- smartpi/color_sensor.pyc +0 -0
- smartpi/cw2015.pyc +0 -0
- smartpi/flash.pyc +0 -0
- smartpi/humidity.pyc +0 -0
- smartpi/led.pyc +0 -0
- smartpi/light_sensor.pyc +0 -0
- smartpi/local_model.pyc +0 -0
- smartpi/mcp_client.pyc +0 -0
- smartpi/mcp_fastmcp.pyc +0 -0
- smartpi/mcp_intent_recognizer.pyc +0 -0
- smartpi/models/__init__.pyc +0 -0
- smartpi/models/snakers4_silero-vad/__init__.pyc +0 -0
- smartpi/models/snakers4_silero-vad/hubconf.pyc +0 -0
- smartpi/motor.pyc +0 -0
- smartpi/move.pyc +0 -0
- smartpi/onnx_hand_workflow.pyc +0 -0
- smartpi/onnx_image_workflow.pyc +0 -0
- smartpi/onnx_pose_workflow.pyc +0 -0
- smartpi/onnx_text_workflow.pyc +0 -0
- smartpi/onnx_voice_workflow.pyc +0 -0
- smartpi/posemodel/__init__.pyc +0 -0
- smartpi/posenet_utils.pyc +0 -0
- smartpi/rknn_hand_workflow.pyc +0 -0
- smartpi/rknn_image_workflow.pyc +0 -0
- smartpi/rknn_pose_workflow.pyc +0 -0
- smartpi/rknn_text_workflow.pyc +0 -0
- smartpi/rknn_voice_workflow.pyc +0 -0
- smartpi/servo.pyc +0 -0
- smartpi/temperature.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/__init__.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/asr/__init__.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/asr/flash_recognizer.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/asr/speech_recognizer.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/common/__init__.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/common/credential.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/common/log.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/common/utils.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/soe/__init__.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/soe/speaking_assessment.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/tts/__init__.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/tts/flowing_speech_synthesizer.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/tts/speech_synthesizer.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/tts/speech_synthesizer_ws.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/vc/__init__.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/vc/speech_convertor_ws.pyc +0 -0
- smartpi/text_gte_model/__init__.pyc +0 -0
- smartpi/text_gte_model/config/__init__.pyc +0 -0
- smartpi/text_gte_model/gte/__init__.pyc +0 -0
- smartpi/touch_sensor.pyc +0 -0
- smartpi/trace.pyc +0 -0
- smartpi/ultrasonic.pyc +0 -0
- {smartpi-1.1.2.dist-info → smartpi-1.1.4.dist-info}/METADATA +1 -1
- smartpi-1.1.4.dist-info/RECORD +77 -0
- smartpi/__init__.py +0 -8
- smartpi/_gui.py +0 -66
- smartpi/ai_asr.py +0 -1037
- smartpi/ai_llm.py +0 -934
- smartpi/ai_tts.py +0 -938
- smartpi/ai_vad.py +0 -83
- smartpi/audio.py +0 -125
- smartpi/base_driver.py +0 -618
- smartpi/camera.py +0 -84
- smartpi/color_sensor.py +0 -18
- smartpi/cw2015.py +0 -179
- smartpi/flash.py +0 -130
- smartpi/humidity.py +0 -20
- smartpi/led.py +0 -19
- smartpi/light_sensor.py +0 -72
- smartpi/local_model.py +0 -432
- smartpi/mcp_client.py +0 -100
- smartpi/mcp_fastmcp.py +0 -322
- smartpi/mcp_intent_recognizer.py +0 -408
- smartpi/models/__init__.py +0 -0
- smartpi/models/snakers4_silero-vad/__init__.py +0 -0
- smartpi/models/snakers4_silero-vad/hubconf.py +0 -56
- smartpi/motor.py +0 -177
- smartpi/move.py +0 -218
- smartpi/onnx_hand_workflow.py +0 -201
- smartpi/onnx_image_workflow.py +0 -176
- smartpi/onnx_pose_workflow.py +0 -482
- smartpi/onnx_text_workflow.py +0 -173
- smartpi/onnx_voice_workflow.py +0 -437
- smartpi/posemodel/__init__.py +0 -0
- smartpi/posenet_utils.py +0 -222
- smartpi/rknn_hand_workflow.py +0 -245
- smartpi/rknn_image_workflow.py +0 -405
- smartpi/rknn_pose_workflow.py +0 -592
- smartpi/rknn_text_workflow.py +0 -240
- smartpi/rknn_voice_workflow.py +0 -394
- smartpi/servo.py +0 -178
- smartpi/temperature.py +0 -18
- smartpi/tencentcloud-speech-sdk-python/__init__.py +0 -1
- smartpi/tencentcloud-speech-sdk-python/asr/__init__.py +0 -0
- smartpi/tencentcloud-speech-sdk-python/asr/flash_recognizer.py +0 -178
- smartpi/tencentcloud-speech-sdk-python/asr/speech_recognizer.py +0 -311
- smartpi/tencentcloud-speech-sdk-python/common/__init__.py +0 -1
- smartpi/tencentcloud-speech-sdk-python/common/credential.py +0 -6
- smartpi/tencentcloud-speech-sdk-python/common/log.py +0 -16
- smartpi/tencentcloud-speech-sdk-python/common/utils.py +0 -7
- smartpi/tencentcloud-speech-sdk-python/soe/__init__.py +0 -0
- smartpi/tencentcloud-speech-sdk-python/soe/speaking_assessment.py +0 -276
- smartpi/tencentcloud-speech-sdk-python/tts/__init__.py +0 -0
- smartpi/tencentcloud-speech-sdk-python/tts/flowing_speech_synthesizer.py +0 -294
- smartpi/tencentcloud-speech-sdk-python/tts/speech_synthesizer.py +0 -144
- smartpi/tencentcloud-speech-sdk-python/tts/speech_synthesizer_ws.py +0 -234
- smartpi/tencentcloud-speech-sdk-python/vc/__init__.py +0 -0
- smartpi/tencentcloud-speech-sdk-python/vc/speech_convertor_ws.py +0 -237
- smartpi/text_gte_model/__init__.py +0 -0
- smartpi/text_gte_model/config/__init__.py +0 -0
- smartpi/text_gte_model/gte/__init__.py +0 -0
- smartpi/touch_sensor.py +0 -16
- smartpi/trace.py +0 -120
- smartpi/ultrasonic.py +0 -20
- smartpi-1.1.2.dist-info/RECORD +0 -77
- {smartpi-1.1.2.dist-info → smartpi-1.1.4.dist-info}/WHEEL +0 -0
- {smartpi-1.1.2.dist-info → smartpi-1.1.4.dist-info}/top_level.txt +0 -0
smartpi/ai_vad.py
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
import sys
|
|
3
|
-
import os
|
|
4
|
-
import time
|
|
5
|
-
import numpy as np
|
|
6
|
-
|
|
7
|
-
class VADProviderBase:
|
|
8
|
-
"""VAD provider base class"""
|
|
9
|
-
@staticmethod
|
|
10
|
-
def create_vad_instance(
|
|
11
|
-
vad_mini_volume=1000,
|
|
12
|
-
vad_mini_length=500,
|
|
13
|
-
vad_pause_timeout=3000,
|
|
14
|
-
vad_silence_timeout=10000,
|
|
15
|
-
threshold=0.02
|
|
16
|
-
):
|
|
17
|
-
"""Factory method to create VAD instance - always returns EnergyVADProvider"""
|
|
18
|
-
# 忽略vad_mini_volume, vad_mini_length, vad_silence_timeout参数
|
|
19
|
-
# 将vad_pause_timeout作为min_silence_duration_ms传递
|
|
20
|
-
return EnergyVADProvider(
|
|
21
|
-
threshold=threshold,
|
|
22
|
-
min_silence_duration_ms=vad_pause_timeout
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
class EnergyVADProvider(VADProviderBase):
|
|
26
|
-
"""Audio energy-based VAD provider"""
|
|
27
|
-
def __init__(self, threshold=0.02, min_silence_duration_ms=300):
|
|
28
|
-
print(f"Initializing EnergyVAD: threshold={threshold}, min_silence_duration_ms={min_silence_duration_ms}")
|
|
29
|
-
# 初始化VAD配置,使用默认值作为备选
|
|
30
|
-
self.vad_threshold = float(threshold) if threshold else 0.02
|
|
31
|
-
self.silence_threshold_ms = int(min_silence_duration_ms) if min_silence_duration_ms else 300
|
|
32
|
-
print("EnergyVAD initialized successfully")
|
|
33
|
-
|
|
34
|
-
def is_vad(self, conn, audio_data):
|
|
35
|
-
"""使用音频能量检测语音活动"""
|
|
36
|
-
try:
|
|
37
|
-
# 确保conn对象有必要的属性
|
|
38
|
-
if not hasattr(conn, 'client_audio_buffer'):
|
|
39
|
-
conn.client_audio_buffer = []
|
|
40
|
-
if not hasattr(conn, 'client_have_voice'):
|
|
41
|
-
conn.client_have_voice = False
|
|
42
|
-
if not hasattr(conn, 'client_have_voice_last_time'):
|
|
43
|
-
conn.client_have_voice_last_time = 0
|
|
44
|
-
if not hasattr(conn, 'client_voice_stop'):
|
|
45
|
-
conn.client_voice_stop = False
|
|
46
|
-
|
|
47
|
-
# 将新数据加入缓冲区
|
|
48
|
-
conn.client_audio_buffer.extend(audio_data)
|
|
49
|
-
|
|
50
|
-
# 处理缓冲区中的数据
|
|
51
|
-
client_have_voice = False
|
|
52
|
-
# 对于能量检测,我们可以使用较小的块大小,例如256采样点
|
|
53
|
-
while len(conn.client_audio_buffer) >= 256 * 2:
|
|
54
|
-
# 提取前256个采样点(512字节)
|
|
55
|
-
chunk = bytes(conn.client_audio_buffer[:256 * 2])
|
|
56
|
-
conn.client_audio_buffer = conn.client_audio_buffer[256 * 2:]
|
|
57
|
-
|
|
58
|
-
# 计算能量
|
|
59
|
-
audio_int16 = np.frombuffer(chunk, dtype=np.int16)
|
|
60
|
-
energy = np.abs(audio_int16).mean()
|
|
61
|
-
|
|
62
|
-
client_have_voice = energy > self.vad_threshold
|
|
63
|
-
|
|
64
|
-
# 更新VAD状态
|
|
65
|
-
if client_have_voice:
|
|
66
|
-
conn.client_have_voice = True
|
|
67
|
-
conn.client_have_voice_last_time = time.time() * 1000
|
|
68
|
-
conn.client_voice_stop = False
|
|
69
|
-
elif conn.client_have_voice:
|
|
70
|
-
# 检查静默时间
|
|
71
|
-
stop_duration = time.time() * 1000 - conn.client_have_voice_last_time
|
|
72
|
-
if stop_duration >= self.silence_threshold_ms:
|
|
73
|
-
conn.client_have_voice = False
|
|
74
|
-
conn.client_voice_stop = True
|
|
75
|
-
|
|
76
|
-
return client_have_voice
|
|
77
|
-
except Exception as e:
|
|
78
|
-
print(f"能量检测出错: {e}")
|
|
79
|
-
return False
|
|
80
|
-
|
|
81
|
-
def reset_states(self):
|
|
82
|
-
"""重置VAD状态"""
|
|
83
|
-
pass # 状态现在存储在conn对象中,不需要在这里重置
|
smartpi/audio.py
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
import os
|
|
3
|
-
import sys
|
|
4
|
-
import subprocess
|
|
5
|
-
import numpy as np
|
|
6
|
-
import math
|
|
7
|
-
|
|
8
|
-
# 全局导入,避免每次调用都重复导入
|
|
9
|
-
import warnings
|
|
10
|
-
warnings.filterwarnings('ignore')
|
|
11
|
-
|
|
12
|
-
# 在导入sounddevice前设置环境变量抑制警告
|
|
13
|
-
os.environ['PYTHONWARNINGS'] = 'ignore'
|
|
14
|
-
|
|
15
|
-
# 导入sounddevice
|
|
16
|
-
import sounddevice as sd
|
|
17
|
-
|
|
18
|
-
def record(seconds, filename="recording.wav"):
|
|
19
|
-
"""
|
|
20
|
-
录音函数
|
|
21
|
-
示例: record(10, "voice.wav")
|
|
22
|
-
"""
|
|
23
|
-
cmd = f"sudo record.sh -d {seconds} {filename}"
|
|
24
|
-
print(f"录音{seconds}秒 -> {filename}")
|
|
25
|
-
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
|
26
|
-
if result.returncode == 0:
|
|
27
|
-
print(f"录音成功: {filename}")
|
|
28
|
-
return True
|
|
29
|
-
else:
|
|
30
|
-
print(f"录音失败: {result.stderr}")
|
|
31
|
-
return False
|
|
32
|
-
|
|
33
|
-
def get_db(sample_time=0.1):
|
|
34
|
-
"""
|
|
35
|
-
检测麦克风分贝值
|
|
36
|
-
返回: 0-100的整数分贝值
|
|
37
|
-
"""
|
|
38
|
-
try:
|
|
39
|
-
# 获取可用设备
|
|
40
|
-
devices = sd.query_devices()
|
|
41
|
-
|
|
42
|
-
# 选择第一个可用的输入设备
|
|
43
|
-
input_device = None
|
|
44
|
-
for i, dev in enumerate(devices):
|
|
45
|
-
if dev['max_input_channels'] > 0:
|
|
46
|
-
input_device = i
|
|
47
|
-
break
|
|
48
|
-
|
|
49
|
-
if input_device is None:
|
|
50
|
-
return 0
|
|
51
|
-
|
|
52
|
-
# 录音参数
|
|
53
|
-
samplerate = 44100
|
|
54
|
-
channels = 1
|
|
55
|
-
duration = sample_time
|
|
56
|
-
|
|
57
|
-
# 录音
|
|
58
|
-
recording = sd.rec(
|
|
59
|
-
int(duration * samplerate),
|
|
60
|
-
samplerate=samplerate,
|
|
61
|
-
channels=channels,
|
|
62
|
-
device=input_device,
|
|
63
|
-
blocking=True,
|
|
64
|
-
dtype='int16'
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
# 转换为numpy数组
|
|
68
|
-
audio_data = recording.flatten()
|
|
69
|
-
|
|
70
|
-
# 过滤静音
|
|
71
|
-
audio_data = audio_data[np.abs(audio_data) > 50]
|
|
72
|
-
|
|
73
|
-
if len(audio_data) == 0:
|
|
74
|
-
return 0
|
|
75
|
-
|
|
76
|
-
# 计算RMS
|
|
77
|
-
rms = np.sqrt(np.mean(np.square(audio_data.astype(np.float32))))
|
|
78
|
-
|
|
79
|
-
# 计算分贝值
|
|
80
|
-
if rms > 0:
|
|
81
|
-
db = 20 * math.log10(rms / 32767.0)
|
|
82
|
-
# 转换为0-100范围并取整
|
|
83
|
-
db_value = max(0, min(100, (db + 60) * (100/60)))
|
|
84
|
-
return int(db_value)
|
|
85
|
-
|
|
86
|
-
return 0
|
|
87
|
-
|
|
88
|
-
except Exception:
|
|
89
|
-
# 发生任何异常返回0
|
|
90
|
-
return 0
|
|
91
|
-
|
|
92
|
-
def play(audio_file):
|
|
93
|
-
"""
|
|
94
|
-
播放音频文件
|
|
95
|
-
示例: play("music.wav")
|
|
96
|
-
"""
|
|
97
|
-
if not os.path.exists(audio_file):
|
|
98
|
-
print(f"文件不存在: {audio_file}")
|
|
99
|
-
return False
|
|
100
|
-
|
|
101
|
-
try:
|
|
102
|
-
subprocess.run(f"aplay {audio_file}", shell=True, check=True)
|
|
103
|
-
return True
|
|
104
|
-
except subprocess.CalledProcessError as e:
|
|
105
|
-
print(f"播放失败: {str(e)}")
|
|
106
|
-
return False
|
|
107
|
-
except Exception as e:
|
|
108
|
-
print(f"播放错误: {str(e)}")
|
|
109
|
-
return False
|
|
110
|
-
|
|
111
|
-
def volume(level=None):
|
|
112
|
-
"""
|
|
113
|
-
调节音量百分比 (0-100)
|
|
114
|
-
示例:
|
|
115
|
-
volume(80) # 设置音量到80%
|
|
116
|
-
current = volume() # 获取当前音量
|
|
117
|
-
"""
|
|
118
|
-
|
|
119
|
-
try:
|
|
120
|
-
level = max(0, min(100, level))
|
|
121
|
-
subprocess.run(['amixer', '-q', 'sset', 'Master', f'{level}%'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
|
122
|
-
return level
|
|
123
|
-
except Exception as e:
|
|
124
|
-
print(f"音量操作错误: {str(e)}")
|
|
125
|
-
return 0 if level is None else level
|