Method: Platform#capture_audio
- Defined in:
- lib/platform/platform.rb
#capture_audio(duration, args = {}) ⇒ Object
Public: Captures audio on the device.
duration - Integer total milliseconds to capture audio. key - String name or Array of keys to press to trigger audio capture (default: nil).
If default, no keys will be pressed.
delay - Integer milliseconds to delay after pressing key and before starting frame capture (default: 0). cleanup - Boolean indicating whether to automatically clean up audio during teardown (default: true).
Returns a Hash with the following keys: :audio - String path to audio file. :start_time - Time at which audio capture began.
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
# File 'lib/platform/platform.rb', line 523 def capture_audio(duration, args={}) key = args[:key] delay = args.fetch(:delay, 0) cleanup = args.fetch(:cleanup, true) press_key(key) unless key.nil? ret = {audio: nil, start_time: Time.now} sleep(delay) if delay > 0 json = get_json_for_iter.merge(block: true, durationMs: duration) resp = @test_case.send(:tmc_post, "/api/audio/record/#{id}", json: json) ret[:audio] = resp['filename'] if cleanup && !ret[:audio].nil? @test_case.add_teardown('Cleaning up captured audio') do delete_files = [ ret[:audio] ] @test_case.send(:tmc_delete, '/api/audio', json: get_json_for_test.merge(files: delete_files)) end end ret end |