hackerbot 0.3.0__py3-none-any.whl → 0.5.0__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.
@@ -69,12 +69,19 @@ class Head():
69
69
 
70
70
  # Setup a sounddevice OutputStream with appropriate parameters
71
71
  # The sample rate and channels should match the properties of the PCM data
72
- stream = sd.OutputStream(samplerate=voice.config.sample_rate, channels=1, dtype='int16')
73
- stream.start()
72
+ stream = sd.OutputStream(
73
+ samplerate=voice.config.sample_rate,
74
+ channels=1,
75
+ dtype='int16',
76
+ blocksize=0 # Let sounddevice choose blocksize automatically
77
+ )
74
78
 
75
- for audio_bytes in voice.synthesize_stream_raw(text, speaker_id = speaker_id):
76
- int_data = np.frombuffer(audio_bytes, dtype=np.int16)
77
- stream.write(int_data)
79
+ with stream: # This automatically handles start/stop/close
80
+ for audio_bytes in voice.synthesize_stream_raw(text, speaker_id=speaker_id):
81
+ int_data = np.frombuffer(audio_bytes, dtype=np.int16)
82
+ stream.write(int_data)
78
83
 
79
- stream.stop()
80
- stream.close()
84
+ # At this point, all data has been written,
85
+ # but we need to wait for any remaining buffered audio to play out.
86
+ stream.stop() # Ensure stream stops cleanly
87
+ print("Finished speaking.") # <-- You now know it's done
@@ -23,6 +23,7 @@ import threading
23
23
  import os
24
24
  import json
25
25
  from collections import deque
26
+ import time
26
27
 
27
28
  class SerialHelper:
28
29
  HOME_DIR = os.environ['HOME']
@@ -39,7 +40,7 @@ class SerialHelper:
39
40
  self.state = None
40
41
  self.ser_error = None
41
42
 
42
- self.json_entries = deque(maxlen=10) # Store up to 10 most recent JSON entries
43
+ self.json_entries = deque(maxlen=20) # Store up to 10 most recent JSON entries
43
44
 
44
45
  try:
45
46
  if self.port is None:
@@ -123,15 +124,20 @@ class SerialHelper:
123
124
  def get_json_from_command(self, command_filter=None):
124
125
  if command_filter is None:
125
126
  raise ValueError("command_filter cannot be None")
126
- if self.json_entries is None or len(self.json_entries) == 0:
127
- raise ValueError("No JSON entries found")
128
-
129
- for entry in reversed(self.json_entries):
130
- if entry.get("command") == command_filter:
131
- if entry.get("success") == "true":
132
- return entry
133
- raise Exception("Fail to fetch...")
134
- raise Exception(f"Command {command_filter} not found in JSON entries")
127
+
128
+ for attempt in range(5):
129
+ if self.json_entries is None or len(self.json_entries) == 0:
130
+ time.sleep(0.1)
131
+ continue
132
+
133
+ for entry in reversed(self.json_entries):
134
+ if entry.get("command") == command_filter:
135
+ if entry.get("success") == "true":
136
+ return entry
137
+ raise Exception("Fail to fetch...")
138
+ time.sleep(0.1)
139
+
140
+ raise Exception(f"Command {command_filter} not found in JSON entries after 5 retries")
135
141
 
136
142
  def stop_read_thread(self):
137
143
  """Call this method to stop the serial reading thread."""
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hackerbot
3
- Version: 0.3.0
3
+ Version: 0.5.0
4
4
  Summary: This module contains the setup for the hackerbot python package.
5
- Author-email: Allen Chien <allen71090@gmail.com>
5
+ Author-email: Allen Chien <allen@hackerbot.co>
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/hackerbotindustries/hackerbot-python-package
8
8
  Requires-Python: >=3.11
@@ -12,9 +12,9 @@ Requires-Dist: pyserial
12
12
  Requires-Dist: pytest
13
13
  Requires-Dist: piper-tts
14
14
  Requires-Dist: sounddevice
15
+ Requires-Dist: pyaudio
15
16
  Dynamic: license-file
16
17
 
17
-
18
18
  # Hackerbot Python Package
19
19
 
20
20
  Hackerbot python package (`hackerbot-python-package`) is a project that includes modules for controlling and managing the Hackerbot system.
@@ -4,12 +4,12 @@ hackerbot/arm/__init__.py,sha256=JdCmTDQ2qk3W8-Alc4mjaQYxHnmH26r0nSy0JFg6J4A,340
4
4
  hackerbot/arm/gripper.py,sha256=xZux0PZL4vvrJTTKHL7dDsRBfJr4zbmgMaA0uBR1u4s,1986
5
5
  hackerbot/base/__init__.py,sha256=PG2Ykn2MLfobAWClGFnp-AZfh1xVsnbc1nQ8E6Yy6eA,8698
6
6
  hackerbot/base/maps.py,sha256=I_4NdvOMnkHX6-mW43QpDPJ-eVc6npgcBXq99tU7D1g,5916
7
- hackerbot/head/__init__.py,sha256=VvKc6Gy3hNARUbFf8HoKkc2TFWoSSswrJbqytvEKUSA,3186
7
+ hackerbot/head/__init__.py,sha256=w4mhnz70miLaChxxF-8bGntDRo8GFLTFICxtTWJX2Iw,3581
8
8
  hackerbot/head/eyes.py,sha256=xqeKMxL12iaa8KQzDlbgbNy3LzcmWm8aXkebztYJ4P8,1370
9
9
  hackerbot/utils/hackerbot_helper.py,sha256=egQPVBBUo52ywsO6jGAGVqhyGLpMPz-b2fgLBb39WSM,4998
10
- hackerbot/utils/serial_helper.py,sha256=l7pj32mnoVZN-7foU_FPUxdmZaE43jcMmZRBAGEX8Zc,6457
11
- hackerbot-0.3.0.dist-info/licenses/LICENSE,sha256=SCcXH0bf35ISRu_Ks8xEKySHXiqclANLWhBUbVU8VvA,1081
12
- hackerbot-0.3.0.dist-info/METADATA,sha256=SNyJO3uVYEOxCbfCs-JkC4ifsuNVd2HGexvpfNzmVos,1766
13
- hackerbot-0.3.0.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
14
- hackerbot-0.3.0.dist-info/top_level.txt,sha256=2n_FStAr1SiI3BV67x7KJHYIOmEwxjUD59zedw2hLkU,10
15
- hackerbot-0.3.0.dist-info/RECORD,,
10
+ hackerbot/utils/serial_helper.py,sha256=qo-mpbE_sb23_IAIfDuRT8sCDtW8d8A8qyav-b9e5Kw,6567
11
+ hackerbot-0.5.0.dist-info/licenses/LICENSE,sha256=SCcXH0bf35ISRu_Ks8xEKySHXiqclANLWhBUbVU8VvA,1081
12
+ hackerbot-0.5.0.dist-info/METADATA,sha256=TjRFtJ_ZSFGW50WkBhwEHlQfNkOXSJWd5wXZgasXoJ0,1786
13
+ hackerbot-0.5.0.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
14
+ hackerbot-0.5.0.dist-info/top_level.txt,sha256=2n_FStAr1SiI3BV67x7KJHYIOmEwxjUD59zedw2hLkU,10
15
+ hackerbot-0.5.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (79.0.0)
2
+ Generator: setuptools (80.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5