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.
Files changed (125) hide show
  1. smartpi/__init__.pyc +0 -0
  2. smartpi/_gui.pyc +0 -0
  3. smartpi/ai_asr.pyc +0 -0
  4. smartpi/ai_llm.pyc +0 -0
  5. smartpi/ai_tts.pyc +0 -0
  6. smartpi/ai_vad.pyc +0 -0
  7. smartpi/audio.pyc +0 -0
  8. smartpi/base_driver.pyc +0 -0
  9. smartpi/camera.pyc +0 -0
  10. smartpi/color_sensor.pyc +0 -0
  11. smartpi/cw2015.pyc +0 -0
  12. smartpi/flash.pyc +0 -0
  13. smartpi/humidity.pyc +0 -0
  14. smartpi/led.pyc +0 -0
  15. smartpi/light_sensor.pyc +0 -0
  16. smartpi/local_model.pyc +0 -0
  17. smartpi/mcp_client.pyc +0 -0
  18. smartpi/mcp_fastmcp.pyc +0 -0
  19. smartpi/mcp_intent_recognizer.pyc +0 -0
  20. smartpi/models/__init__.pyc +0 -0
  21. smartpi/models/snakers4_silero-vad/__init__.pyc +0 -0
  22. smartpi/models/snakers4_silero-vad/hubconf.pyc +0 -0
  23. smartpi/motor.pyc +0 -0
  24. smartpi/move.pyc +0 -0
  25. smartpi/onnx_hand_workflow.pyc +0 -0
  26. smartpi/onnx_image_workflow.pyc +0 -0
  27. smartpi/onnx_pose_workflow.pyc +0 -0
  28. smartpi/onnx_text_workflow.pyc +0 -0
  29. smartpi/onnx_voice_workflow.pyc +0 -0
  30. smartpi/posemodel/__init__.pyc +0 -0
  31. smartpi/posenet_utils.pyc +0 -0
  32. smartpi/rknn_hand_workflow.pyc +0 -0
  33. smartpi/rknn_image_workflow.pyc +0 -0
  34. smartpi/rknn_pose_workflow.pyc +0 -0
  35. smartpi/rknn_text_workflow.pyc +0 -0
  36. smartpi/rknn_voice_workflow.pyc +0 -0
  37. smartpi/servo.pyc +0 -0
  38. smartpi/temperature.pyc +0 -0
  39. smartpi/tencentcloud-speech-sdk-python/__init__.pyc +0 -0
  40. smartpi/tencentcloud-speech-sdk-python/asr/__init__.pyc +0 -0
  41. smartpi/tencentcloud-speech-sdk-python/asr/flash_recognizer.pyc +0 -0
  42. smartpi/tencentcloud-speech-sdk-python/asr/speech_recognizer.pyc +0 -0
  43. smartpi/tencentcloud-speech-sdk-python/common/__init__.pyc +0 -0
  44. smartpi/tencentcloud-speech-sdk-python/common/credential.pyc +0 -0
  45. smartpi/tencentcloud-speech-sdk-python/common/log.pyc +0 -0
  46. smartpi/tencentcloud-speech-sdk-python/common/utils.pyc +0 -0
  47. smartpi/tencentcloud-speech-sdk-python/soe/__init__.pyc +0 -0
  48. smartpi/tencentcloud-speech-sdk-python/soe/speaking_assessment.pyc +0 -0
  49. smartpi/tencentcloud-speech-sdk-python/tts/__init__.pyc +0 -0
  50. smartpi/tencentcloud-speech-sdk-python/tts/flowing_speech_synthesizer.pyc +0 -0
  51. smartpi/tencentcloud-speech-sdk-python/tts/speech_synthesizer.pyc +0 -0
  52. smartpi/tencentcloud-speech-sdk-python/tts/speech_synthesizer_ws.pyc +0 -0
  53. smartpi/tencentcloud-speech-sdk-python/vc/__init__.pyc +0 -0
  54. smartpi/tencentcloud-speech-sdk-python/vc/speech_convertor_ws.pyc +0 -0
  55. smartpi/text_gte_model/__init__.pyc +0 -0
  56. smartpi/text_gte_model/config/__init__.pyc +0 -0
  57. smartpi/text_gte_model/gte/__init__.pyc +0 -0
  58. smartpi/touch_sensor.pyc +0 -0
  59. smartpi/trace.pyc +0 -0
  60. smartpi/ultrasonic.pyc +0 -0
  61. {smartpi-1.1.2.dist-info → smartpi-1.1.4.dist-info}/METADATA +1 -1
  62. smartpi-1.1.4.dist-info/RECORD +77 -0
  63. smartpi/__init__.py +0 -8
  64. smartpi/_gui.py +0 -66
  65. smartpi/ai_asr.py +0 -1037
  66. smartpi/ai_llm.py +0 -934
  67. smartpi/ai_tts.py +0 -938
  68. smartpi/ai_vad.py +0 -83
  69. smartpi/audio.py +0 -125
  70. smartpi/base_driver.py +0 -618
  71. smartpi/camera.py +0 -84
  72. smartpi/color_sensor.py +0 -18
  73. smartpi/cw2015.py +0 -179
  74. smartpi/flash.py +0 -130
  75. smartpi/humidity.py +0 -20
  76. smartpi/led.py +0 -19
  77. smartpi/light_sensor.py +0 -72
  78. smartpi/local_model.py +0 -432
  79. smartpi/mcp_client.py +0 -100
  80. smartpi/mcp_fastmcp.py +0 -322
  81. smartpi/mcp_intent_recognizer.py +0 -408
  82. smartpi/models/__init__.py +0 -0
  83. smartpi/models/snakers4_silero-vad/__init__.py +0 -0
  84. smartpi/models/snakers4_silero-vad/hubconf.py +0 -56
  85. smartpi/motor.py +0 -177
  86. smartpi/move.py +0 -218
  87. smartpi/onnx_hand_workflow.py +0 -201
  88. smartpi/onnx_image_workflow.py +0 -176
  89. smartpi/onnx_pose_workflow.py +0 -482
  90. smartpi/onnx_text_workflow.py +0 -173
  91. smartpi/onnx_voice_workflow.py +0 -437
  92. smartpi/posemodel/__init__.py +0 -0
  93. smartpi/posenet_utils.py +0 -222
  94. smartpi/rknn_hand_workflow.py +0 -245
  95. smartpi/rknn_image_workflow.py +0 -405
  96. smartpi/rknn_pose_workflow.py +0 -592
  97. smartpi/rknn_text_workflow.py +0 -240
  98. smartpi/rknn_voice_workflow.py +0 -394
  99. smartpi/servo.py +0 -178
  100. smartpi/temperature.py +0 -18
  101. smartpi/tencentcloud-speech-sdk-python/__init__.py +0 -1
  102. smartpi/tencentcloud-speech-sdk-python/asr/__init__.py +0 -0
  103. smartpi/tencentcloud-speech-sdk-python/asr/flash_recognizer.py +0 -178
  104. smartpi/tencentcloud-speech-sdk-python/asr/speech_recognizer.py +0 -311
  105. smartpi/tencentcloud-speech-sdk-python/common/__init__.py +0 -1
  106. smartpi/tencentcloud-speech-sdk-python/common/credential.py +0 -6
  107. smartpi/tencentcloud-speech-sdk-python/common/log.py +0 -16
  108. smartpi/tencentcloud-speech-sdk-python/common/utils.py +0 -7
  109. smartpi/tencentcloud-speech-sdk-python/soe/__init__.py +0 -0
  110. smartpi/tencentcloud-speech-sdk-python/soe/speaking_assessment.py +0 -276
  111. smartpi/tencentcloud-speech-sdk-python/tts/__init__.py +0 -0
  112. smartpi/tencentcloud-speech-sdk-python/tts/flowing_speech_synthesizer.py +0 -294
  113. smartpi/tencentcloud-speech-sdk-python/tts/speech_synthesizer.py +0 -144
  114. smartpi/tencentcloud-speech-sdk-python/tts/speech_synthesizer_ws.py +0 -234
  115. smartpi/tencentcloud-speech-sdk-python/vc/__init__.py +0 -0
  116. smartpi/tencentcloud-speech-sdk-python/vc/speech_convertor_ws.py +0 -237
  117. smartpi/text_gte_model/__init__.py +0 -0
  118. smartpi/text_gte_model/config/__init__.py +0 -0
  119. smartpi/text_gte_model/gte/__init__.py +0 -0
  120. smartpi/touch_sensor.py +0 -16
  121. smartpi/trace.py +0 -120
  122. smartpi/ultrasonic.py +0 -20
  123. smartpi-1.1.2.dist-info/RECORD +0 -77
  124. {smartpi-1.1.2.dist-info → smartpi-1.1.4.dist-info}/WHEEL +0 -0
  125. {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