I am using arecord through subprocess to record in raspberry pi : press joystick button to start recording and press button again to stop recording, It works randomly: when I press the button, the background picture changes successfully but sometimes it couldn't record. really strange to me.

 #detect button press
 if joystick.get_numbuttons() >= 1 and joystick.get_button( 0 ) == 0 and button_pressed:
button_pressed = False
is_recording = not is_recording

#start recording
if is_recording:
    dotting = dotting + 1
    #recording code
    filename = "%s.wav" % datetime.now().strftime("%Y%m%d_%H%M%S")
    p=subprocess.Popen(['arecord', '--device=hw:1,0', '--format', 'S16_LE', '--rate', '44100-c1', filename], shell=False)

    #change background
    background = pygame.image.load(background_image2).convert()
    #start timer
    stopFlag = Event()
    timer = MyTimer(stopFlag,time.clock())
    text2 = font.render('.', True, BLACK)

    screen.blit(background, (0,0))


    #record, remaining here

#stop recording
    #stop recording, save record

    #back to previous question
    timer.do_run = False
    background = pygame.image.load(background_image).convert()
    #kill console
    #os.killpg(os.getpgid(p.pid), signal.SIGTERM
  • arecord could be reporting an error, but since you're not capturing stdout, stderr, or the return code it's hard to tell what it is. Try capturing those in Python and printing out each time and update your post with that info. If arecord always returns a success code and isn't printing an error, check dmesg for errors as well. – jdonald Nov 20 '17 at 17:51
  • thanks, i am really a noob in programming and python, I googled "stdout" and "stderr" and find saltycrane.com/blog/2008/09/… which talks about how stdout and stderr works . I will this first. much thanks. – Cun Li Nov 20 '17 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.