#! /usr/bin/env python
#-*- coding: utf-8 -*-
#################################################################
#   Copyright (C) 2015 Sean Guo. All rights reserved.
#														  
#	> File Name:        < record.py >
#	> Author:           < Sean Guo >		
#	> Mail:             < iseanxp+code@gmail.com >		
#	> Created Time:     < 2015/04/03 >
#	> Last Changed: 
#	> Description:		Nao机器人录音模块
#################################################################

'''
	录音一段时间，再播放录音
'''

import argparse
from naoqi import ALProxy
import time
tts = audio = record = aup = None 

def main(robot_IP, robot_PORT=9559):
	global tts, audio, record, aup 
	# ----------> Connect to robot <----------
	tts = ALProxy("ALTextToSpeech", robot_IP, robot_PORT)
	audio = ALProxy("ALAudioDevice", robot_IP, robot_PORT)
	record = ALProxy("ALAudioRecorder", robot_IP, robot_PORT)
	aup = ALProxy("ALAudioPlayer", robot_IP, robot_PORT)
	# ----------> recording <----------
	print 'start recording...'
	record_path = '~/ICRL/nao-setup/PythonScriptSummer16/test.wav'
	record.startMicrophonesRecording(record_path, 'wav', 16000, (0,0,1,0))
	time.sleep(10)
	record.stopMicrophonesRecording()
	print 'record over'


	# ----------> playing the recorded file <----------
	fileID = aup.playFile(record_path, 0.7, 0)	

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="nico.d.mtholyoke.edu", help="Robot ip address")
    parser.add_argument("--port", type=int, default=9559, help="Robot port number")
    args = parser.parse_args()
	# ----------> 执行main函数 <----------
    main(args.ip, args.port)
