Created
March 29, 2017 14:04
-
-
Save ptr-yudai/bcd2576f88759cc5cd6c4dbcba0e5bd2 to your computer and use it in GitHub Desktop.
[LINUX] Voice Recorder for TOEFL Speaking Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple Voice Recorder for TOELF Speaking Test | |
# Usage: | |
# python record.py [output.wav] | |
# Requirement: | |
# Python 2, arecord (often pre-installed on linux) | |
# What does this program do? | |
# First, this program will wait 15 seconds, which is the same length given in the TEFL test for preparing your answer. | |
# Second, arecord will begin to record your voice for 45 seconds in which you need to answer the question. | |
# After that, the recorded voice will be saved as a wav file. | |
# Optionally, you can listen to the recorded voice after your answer. | |
import subprocess | |
from subprocess import Popen | |
import os | |
from os import path | |
import time | |
import sys | |
if len(sys.argv) < 2: | |
print("Output filepath required.") | |
exit(1) | |
pre_limit = 15 | |
limit = 45 | |
output = sys.argv[1] | |
cmd = "arecord -d {0} -f cd {1}".format(limit, output) | |
if path.exists(output): | |
print("Output file already exists.") | |
exit(1) | |
print("Prepare for your answer in {0} seconds.".format(pre_limit)) | |
for i in range(pre_limit): | |
print("{0} seconds left".format(pre_limit-i)) | |
time.sleep(1) | |
print("Answer the question...") | |
proc = Popen(cmd, shell=True) | |
for i in range(limit): | |
time.sleep(1) | |
if i == 0: print("START") | |
print("{0} seconds left".format(limit - i)) | |
print("END") | |
proc.wait() | |
time.sleep(1) | |
# If you want to listen to the recorded voice, | |
# comment out the following line and change 'vlc' into the program name of your sound player. | |
#os.system("vlc ./".format(output)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment