def test_recorder_record_success(self): scheduler = Mock(BlockingScheduler) scheduler.get_jobs.return_value = [] hdhomerun = Mock(HDHomeRunInterface) db = Mock(CarbonDVRDatabase) db.getPendingRecordings.return_value = [] recorder = Recorder(scheduler, hdhomerun, db, 'rec/recording_{recordingID}.mp4', 'logs/recording_{recordingID}.log') recorder.logger = Mock() schedule = Bunch(channelMajor=1, channelMinor=2, startTime=datetime(1970, 1, 1, 0, 0, 0), duration=timedelta(minutes=47), showID='show1', episodeID='episode1', rerunCode='R') db.getUniqueID.return_value = 3 recorder.record(schedule) db.insertRecording.assert_called_once_with(3, 'show1', 'episode1', timedelta(minutes=47), 'R') hdhomerun.record.assert_called_once_with( 1, 2, datetime(1970, 1, 1, 0, 0, 0) + timedelta(minutes=47), 'rec/recording_3.mp4', 'logs/recording_3.log') db.insertRawVideoLocation.assert_called_once_with( 3, 'rec/recording_3.mp4')
def main(): """ load the environment variables """ dotenv_path = join(dirname(__file__), '.env') load_dotenv(dotenv_path) """ initialize the speech to text service """ stt = SpeechToText( username=os.environ.get("STT_USERNAME"), password=os.environ.get("STT_PASSWORD")) """ initialize the recorder, provide a filename to save it as """ recorder = Recorder("speech.wav") print("How can I help you?\n") recorder.record_to_file() print("Transcribing audio....\n") result = transcribe_audio(stt, 'speech.wav') text = result['results'][0]['alternatives'][0]['transcript'] print("Text: " + text + "\n")
def test_recorder_record_fail(self): scheduler = Mock(BlockingScheduler) scheduler.get_jobs.return_value = [] hdhomerun = Mock(HDHomeRunInterface) db = Mock(CarbonDVRDatabase) db.getPendingRecordings.return_value = [] recorder = Recorder( scheduler, hdhomerun, db, '/var/spool/carbondvr/recordings/raw_{recordingID}.mp4', '/var/log/carbondvr/recordings/rec{recordingID}.log') recorder.logger = Mock() schedule = Bunch(channelMajor=8, channelMinor=3, startTime=datetime(1992, 12, 21, 16, 57, 19), duration=timedelta(minutes=15), showID='show2', episodeID='episode2', rerunCode='N') db.getUniqueID.return_value = 58162 hdhomerun.record.side_effect = BadRecordingException() recorder.record(schedule) db.insertRecording.assert_called_once_with(58162, 'show2', 'episode2', timedelta(minutes=15), 'N') hdhomerun.record.assert_called_once_with( 8, 3, datetime(1992, 12, 21, 16, 57, 19) + timedelta(minutes=15), '/var/spool/carbondvr/recordings/raw_58162.mp4', '/var/log/carbondvr/recordings/rec58162.log') self.assertFalse(db.insertRawVideoLocation.called)
def record_and_save(): global recorder if recorder.is_recording(): return "Already recording" else: recorder = Recorder(audio_properties) recorder.start() return "Recording"
def test_recorder_record_success(self): scheduler = Mock(BlockingScheduler) scheduler.get_jobs.return_value = [] hdhomerun = Mock(HDHomeRunInterface) db = Mock(CarbonDVRDatabase) db.getPendingRecordings.return_value = [] recorder = Recorder(scheduler, hdhomerun, db, 'rec/recording_{recordingID}.mp4', 'logs/recording_{recordingID}.log') recorder.logger = Mock() schedule = Bunch(channelMajor=1, channelMinor=2, startTime=datetime(1970,1,1,0,0,0), duration=timedelta(minutes=47), showID='show1', episodeID='episode1', rerunCode='R') db.getUniqueID.return_value = 3 recorder.record(schedule) db.insertRecording.assert_called_once_with(3, 'show1', 'episode1', timedelta(minutes=47), 'R') hdhomerun.record.assert_called_once_with(1, 2, datetime(1970,1,1,0,0,0) + timedelta(minutes=47), 'rec/recording_3.mp4', 'logs/recording_3.log') db.insertRawVideoLocation.assert_called_once_with(3, 'rec/recording_3.mp4')
def test_recorder_record_fail(self): scheduler = Mock(BlockingScheduler) scheduler.get_jobs.return_value = [] hdhomerun = Mock(HDHomeRunInterface) db = Mock(CarbonDVRDatabase) db.getPendingRecordings.return_value = [] recorder = Recorder(scheduler, hdhomerun, db, '/var/spool/carbondvr/recordings/raw_{recordingID}.mp4', '/var/log/carbondvr/recordings/rec{recordingID}.log') recorder.logger = Mock() schedule = Bunch(channelMajor=8, channelMinor=3, startTime=datetime(1992,12,21,16,57,19), duration=timedelta(minutes=15), showID='show2', episodeID='episode2', rerunCode='N') db.getUniqueID.return_value = 58162 hdhomerun.record.side_effect=BadRecordingException() recorder.record(schedule) db.insertRecording.assert_called_once_with(58162, 'show2', 'episode2', timedelta(minutes=15), 'N') hdhomerun.record.assert_called_once_with(8, 3, datetime(1992,12,21,16,57,19) + timedelta(minutes=15), '/var/spool/carbondvr/recordings/raw_58162.mp4', '/var/log/carbondvr/recordings/rec58162.log') self.assertFalse(db.insertRawVideoLocation.called)
def main(): dotenv_path = join(dirname(__file__), '.env') load_dotenv(dotenv_path) stt = SpeechToText(username=os.environ.get("STT_USERNAME"), password=os.environ.get("STT_PASSWORD")) recorder = Recorder("speech.wav") print("Please say something into the microphone\n") recorder.record_to_file() print("Transcribing audio....\n") result = transcribe_audio(stt, 'speech.wav') text = result['results'][0]['alternatives'][0]['transcript'] print("Text: " + text + "\n")
def test_recorder_removeAllRecordingJobs(self): scheduler = Mock(BlockingScheduler) scheduler.get_jobs.return_value = [] hdhomerun = Mock(HDHomeRunInterface) db = Mock(CarbonDVRDatabase) db.getPendingRecordings.return_value = [] recorder = Recorder(scheduler, hdhomerun, db, 'recs', 'logs') recorder.logger = Mock() recorder.scheduler = Mock() # given: a mix of recording jobs and non-recording jobs recorder.scheduler.get_jobs.return_value = [ Bunch(func=recorder.record, id=3), Bunch(func=recorder.scheduleRecordings, id=1), Bunch(func=recorder.record, id=4) ] # when: removeAllRecordingJobs recorder.removeAllRecordingJobs() # then: all recording jobs removed, non-recording jobs ignored self.assertEqual(2, recorder.scheduler.remove_job.call_count) self.assertEqual(recorder.scheduler.remove_job.call_args_list[0], call(3)) self.assertEqual(recorder.scheduler.remove_job.call_args_list[1], call(4))
def add_recorder(_env, args: SimArgs): if args.is_remote_client: main_args = args.client_main_args else: main_args = c.MAIN_ARGS _env.recorder = Recorder(args.recording_dir, should_record=args.should_record, eval_only=args.eval_only, should_upload_gist=args.upload_gist, public=args.public, main_args=main_args, is_botleague=args.is_botleague)
def test_recorder_scheduleRecordings(self): scheduler = Mock(BlockingScheduler) scheduler.get_jobs.return_value = [] hdhomerun = Mock(HDHomeRunInterface) db = Mock(CarbonDVRDatabase) db.getPendingRecordings.return_value = [] recorder = Recorder(scheduler, hdhomerun, db, 'recs', 'logs') recorder.logger = Mock() recorder.scheduler = Mock() recorder.removeAllRecordingJobs = Mock() # given: a set of pending recordings mockPendingRecordings = [ Bunch(channelMajor=1, channelMinor=2, startTime=datetime(2000,1,1,12,00,00, tzinfo=pytz.timezone('US/Central'))), Bunch(channelMajor=19, channelMinor=3, startTime=datetime(2000,1,1,13,00,00, tzinfo=pytz.timezone('US/Central'))), Bunch(channelMajor=38, channelMinor=1, startTime=datetime(2000,1,1,14,00,00, tzinfo=pytz.timezone('US/Central'))) ] db.getPendingRecordings.reset_mock() db.getPendingRecordings.return_value = mockPendingRecordings # when: scheduleRecordings recorder.scheduleRecordings() # then: all existing recording jobs cleared, getPendingRecordings is called, new recording jobs are added recorder.removeAllRecordingJobs.assert_called_once() db.getPendingRecordings.assert_called_once_with(timedelta(hours=12)) self.assertEqual(3, recorder.scheduler.add_job.call_count) call0 = call(recorder.record, args=[mockPendingRecordings[0]], trigger='date', run_date=mockPendingRecordings[0].startTime, misfire_grace_time=60) self.assertEqual(recorder.scheduler.add_job.call_args_list[0], call0) call1 = call(recorder.record, args=[mockPendingRecordings[1]], trigger='date', run_date=mockPendingRecordings[1].startTime, misfire_grace_time=60) self.assertEqual(recorder.scheduler.add_job.call_args_list[1], call1) call2 = call(recorder.record, args=[mockPendingRecordings[2]], trigger='date', run_date=mockPendingRecordings[2].startTime, misfire_grace_time=60) self.assertEqual(recorder.scheduler.add_job.call_args_list[2], call2)
""" Created on Jun 1, 2018 @author: Nebojsa """ from flask import Flask, Response from model.audioproperties import AudioProperties from recorder.recorder import Recorder from udp_sender.udp_sender import UDPSender if __name__ == '__main__': app = Flask(__name__) recorder = Recorder() audio_properties = AudioProperties() udp_sender = UDPSender() udp_sender.start() port = 63000 @app.route('/record') def record_and_save(): global recorder if recorder.is_recording(): return "Already recording" else: recorder = Recorder(audio_properties) recorder.start() return "Recording"
def __init__(self, debug): self.registrar = Registrar(debug) self.selector = Selector(debug) self.scheduler = Scheduler(debug) self.recorder = Recorder(debug)
def record_mode(file_name): print("Recording mode has been activated.") recorder = Recorder(file_name) recorder.record()
""" media_q = Queue() pmh = PypoMessageHandler(pypoFetch_q, recorder_q, config) pmh.daemon = True pmh.start() pfile = PypoFile(media_q, config) pfile.daemon = True pfile.start() pf = PypoFetch(pypoFetch_q, pypoPush_q, media_q, pypo_liquidsoap, config) pf.daemon = True pf.start() pp = PypoPush(pypoPush_q, pypo_liquidsoap) pp.daemon = True pp.start() recorder = Recorder(recorder_q) recorder.daemon = True recorder.start() stat = ListenerStat() stat.daemon = True stat.start() pf.join() logger.info("System exit")
def test_recorder_scheduleRecordings(self): scheduler = Mock(BlockingScheduler) scheduler.get_jobs.return_value = [] hdhomerun = Mock(HDHomeRunInterface) db = Mock(CarbonDVRDatabase) db.getPendingRecordings.return_value = [] recorder = Recorder(scheduler, hdhomerun, db, 'recs', 'logs') recorder.logger = Mock() recorder.scheduler = Mock() recorder.removeAllRecordingJobs = Mock() # given: a set of pending recordings mockPendingRecordings = [ Bunch(channelMajor=1, channelMinor=2, startTime=datetime(2000, 1, 1, 12, 00, 00, tzinfo=pytz.timezone('US/Central'))), Bunch(channelMajor=19, channelMinor=3, startTime=datetime(2000, 1, 1, 13, 00, 00, tzinfo=pytz.timezone('US/Central'))), Bunch(channelMajor=38, channelMinor=1, startTime=datetime(2000, 1, 1, 14, 00, 00, tzinfo=pytz.timezone('US/Central'))) ] db.getPendingRecordings.reset_mock() db.getPendingRecordings.return_value = mockPendingRecordings # when: scheduleRecordings recorder.scheduleRecordings() # then: all existing recording jobs cleared, getPendingRecordings is called, new recording jobs are added recorder.removeAllRecordingJobs.assert_called_once() db.getPendingRecordings.assert_called_once_with(timedelta(hours=12)) self.assertEqual(3, recorder.scheduler.add_job.call_count) call0 = call(recorder.record, args=[mockPendingRecordings[0]], trigger='date', run_date=mockPendingRecordings[0].startTime, misfire_grace_time=60) self.assertEqual(recorder.scheduler.add_job.call_args_list[0], call0) call1 = call(recorder.record, args=[mockPendingRecordings[1]], trigger='date', run_date=mockPendingRecordings[1].startTime, misfire_grace_time=60) self.assertEqual(recorder.scheduler.add_job.call_args_list[1], call1) call2 = call(recorder.record, args=[mockPendingRecordings[2]], trigger='date', run_date=mockPendingRecordings[2].startTime, misfire_grace_time=60) self.assertEqual(recorder.scheduler.add_job.call_args_list[2], call2)