Skip to content

Commit a6ab160

Browse files
committed
modified some details
1 parent 40c82d7 commit a6ab160

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

examples/raspi_assistant/handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ def default(base_handler, result):
8888
@staticmethod
8989
def _memo(date, base_handler):
9090
base_handler.feedback('请说出记录内容')
91-
base_handler.audio_handler.arecord(6)
91+
audio = base_handler.audio_handler.arecord(6, is_buffer=True)
9292
cache_handler = CacheHandler()
93-
cache_handler.zset(date, f.read(), timestamp(), 86400*3)
93+
cache_handler.zset(date, audio, timestamp(), 86400*3)
9494
return '完成记录'
9595

9696
@staticmethod
@@ -113,7 +113,7 @@ def play_memo(date, base_handler):
113113
audio = cache_handler.zget(date, 0, -1)
114114
if audio:
115115
for item in audio:
116-
base_handler.audio_handler.aplay(audio)
116+
base_handler.audio_handler.aplay(audio, is_buffer=True)
117117
return '播放结束'
118118
else:
119119
base_handler.feedback('未找到记录')

examples/raspi_assistant/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,21 @@ def record(self, record_seconds, file_):
148148
wf.writeframes(''.join(frames))
149149
wf.close()
150150

151-
def arecord(self, record_seconds, is_temp=False, file_=BC.INPUT_NAME):
152-
if is_temp:
151+
def arecord(self, record_seconds, is_buffer=False, file_=BC.INPUT_NAME):
152+
if is_buffer:
153153
p = Popen(
154154
['arecord', '-r', '16000', '-D', 'plughw:1,0', '-f', 'S16_LE', '-d', str(record_seconds), '-'],
155155
stdout=PIPE,
156156
stderr=PIPE)
157-
stdin, _ = p.communicate()
158-
return stdin
157+
stdout, _ = p.communicate()
158+
return stdout
159159
else:
160160
p = Popen(
161161
['arecord', '-r', '16000', '-D', 'plughw:1,0', '-f', 'S16_LE', '-d', str(record_seconds), file_])
162162
p.wait()
163163

164-
def aplay(self, is_temp=False, file_=BC.OUTPUT_NAME):
165-
if is_temp:
164+
def aplay(self, is_buffer=False, file_=BC.OUTPUT_NAME):
165+
if is_buffer:
166166
p = Popen(['aplay', '-'], stdin=file_)
167167
else:
168168
p = Popen(['aplay', file_])

0 commit comments

Comments
 (0)