Best Python code snippet using robotframework-appiumlibrary_python
screen_recorder.py
Source:screen_recorder.py  
...31        screen_thread.start()32        message_dialog(33            title='Recording ..',34            text='Click OK when you want to stop recording\n').run()35        self.stop_screen_recording() 36        screen_thread.join()37           38        self.stop_audio_recording()39        audio_thread.join()40  41        self.screen_stream.release()42        self.save_recording()43    def select_audio_device(self):44        """45        Select Audio Device from list of available microphones. Check based on input channels.46        """47        info = self.audio_plugin.get_host_api_info_by_index(0)48        numdevices = info.get('deviceCount')49        available_audio_devices = []50        for i in range(0, numdevices):51                if (self.audio_plugin.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0:52                    available_audio_devices.append((i, self.audio_plugin.get_device_info_by_host_api_device_index(0, i).get('name')))53        self.selected_device = radiolist_dialog(54            title='Microphone Selector',55            text='Select your microphone to record',56            values=available_audio_devices,57        ).run()58        print("Selected Device ID:", self.selected_device)59    def set_recording_info(self):60        """61        Set info for stream recorder62        """63        # Audio Stream64        self.audio_frames = []65        self.chunk = 1024  # Record in chunks of 1024 samples66        self.sample_format = pyaudio.paInt16  # 16 bits per sample67        self.channels = 268        self.fs = 44100  # Record at 44100 samples per second69        self.audio_stream = self.audio_plugin.open(format=self.sample_format,70                        channels=self.channels,71                        rate=self.fs,72                        frames_per_buffer=self.chunk,73                input=True, input_device_index=self.selected_device, stream_callback=self.callback_function())      74        75        # Screen Capture stream76        self.screenWidth, self.screenHeight = pyautogui.size()77        print(self.screenWidth, self.screenHeight)78        self.filename = 'intermediate.mp4'79        fourcc = cv2.VideoWriter_fourcc(*'mp4v')80        self.screen_stream = cv2.VideoWriter(self.filename, fourcc, 10, (int(self.screenWidth), int(self.screenHeight)))81        print('Initializing Stream')82    def terminate(self):83        self._recording = False84    def callback_function(self):85        def callback(in_data, frame_count, time_info, status):86            self.audio_frames.append(in_data)87            return in_data, pyaudio.paContinue88        return callback89    def start_audio_recording(self):90        """91        Begin recording on dialog accept92        """93        self.audio_stream.start_stream()94    def start_screen_recording(self):95        """96        Begin recording on dialog accept97        """98      99        self._recording = True100        time.sleep(0.5)101        while self._recording:102            screen = np.asarray(pyautogui.screenshot())103            screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB)104            self.screen_stream.write(screen)105    def stop_audio_recording(self):106        """107        Destroy stream objects108        """109        self.audio_stream.stop_stream()110        self.audio_stream.close()111        self.audio_plugin.terminate()        112    def stop_screen_recording(self):113        """114        Destroy stream objects115        """116        self.terminate()117    def save_recording(self):118        """119        Save recording, open dialog for filename120        """121        self.filename = input_dialog(122            title='Save recording',123            text='Enter filename to save recording, *.mp4').run()124        if self.filename is not None:125            wf = wave.open("intermediate.wav", 'wb')126            wf.setnchannels(self.channels)..._screenrecord.py
Source:_screenrecord.py  
...29        self._output_format = self._set_output_format() \30            if self._output_format is None else self._output_format31        if self._recording is None:32            self._recording = self._current_application().start_recording_screen(**options)33    def stop_screen_recording(self, filename=None, **options):34        """Gathers the output from the previously started screen recording  \35            to a media file, then embeds it to the log.html(only on Android).36        Requires an active or exhausted Screen Recording Session.37        See `Start Screen Recording` for more details.38        Example:39            | `Start Screen Recording`  |                   | # starts a screen record session  |40            | ....     keyword actions  |                   |                                   |41            | `Stop Screen Recording`   | filename=output   | # saves the recorded session      |42        """43        if self._recording is not None:44            self._recording = self._current_application().stop_recording_screen(**options)45            return self._save_recording(filename)46        else:47            raise RuntimeError("There is no Active Screen Record Session.")...ScreenRecorder.py
Source:ScreenRecorder.py  
...47        out.release()48        self.file_handler.file_send(file=file)49        os.remove(file)5051    def stop_screen_recording(self):
...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
