google / aiyprojects-raspbian

API libraries, samples, and system images for AIY Projects (Voice Kit and Vision Kit)

Home Page:https://aiyprojects.withgoogle.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Huge delay in voice recording.

tisrico opened this issue · comments

Added some prints in the "./src/aiy/voice/audio.py" and found that it took over 4 seconds before it started the actual recording. So this is the reason why it never really passed the test "/home/pi/AIY-projects-python/checkpoints/check_audio.py", because in this script, it only waits for 3 seconds for recording.

Change made:

diff --git a/src/aiy/voice/audio.py b/src/aiy/voice/audio.py
index 0b46b3c..119a86d 100644
--- a/src/aiy/voice/audio.py
+++ b/src/aiy/voice/audio.py
@@ -124,7 +124,8 @@ def arecord(fmt, filetype='raw', filename=None, device='default'):
     if filetype not in SUPPORTED_FILETYPES:
         raise ValueError('File type must be %s.' % ', '.join(SUPPORTED_FILETYPES))

-    cmd = ['arecord', '-q',
+    #cmd = ['arecord', '-q',
+    cmd = ['arecord',
            '-D', device,
            '-t', filetype,
            '-c', str(fmt.num_channels),
@@ -184,6 +185,7 @@ def record_file_async(fmt, filename, filetype, device='default'):
         raise ValueError('Filetype must be specified.')

     cmd = arecord(fmt, filetype=filetype, filename=filename, device=device)
+    print(cmd)
     return subprocess.Popen(cmd)

Test log:

pi@raspberrypi:~/AIY-projects-python/src/examples/voice $ ./voice_recorder.py
Press button to start recording.
['arecord', '-D', 'default', '-t', 'wav', '-c', '2', '-f', 's16', '-r', '44100', 'recording.wav']
Recording: 0.00 seconds [Press button to stop]
Recording: 0.50 seconds [Press button to stop]
Recording: 1.01 seconds [Press button to stop]
Recording: 1.51 seconds [Press button to stop]
Recording: 2.01 seconds [Press button to stop]
Recording: 2.51 seconds [Press button to stop]
Recording: 3.02 seconds [Press button to stop]
Recording: 3.52 seconds [Press button to stop]
Recording: 4.02 seconds [Press button to stop]
Recording WAVE 'recording.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Recording: 4.53 seconds [Press button to stop]
Recording: 5.03 seconds [Press button to stop]
Recording: 5.53 seconds [Press button to stop]
Recording: 6.04 seconds [Press button to stop]
Recording: 6.54 seconds [Press button to stop]
Recording: 7.04 seconds [Press button to stop]
Recording: 7.54 seconds [Press button to stop]
Recording: 8.05 seconds [Press button to stop]
Aborted by signal Terminated...
Press button to play recorded sound.
Playing...
Done.

Environment: voice kit V2, loaded with the latest 2021 image.
Any one please help!

The issue is not reproducible using hdmi/mouse/keyboard on the kit, it seems it is related to my terminal software's settings on X11-Forwarding. With X11-Fordwarding turned off, I can perform the test using ssh as well.

So, the issue has been resolved and this can be closed.