Best Python code snippet using hypothesis
RecordUtil.py
Source: RecordUtil.py
1# -*- coding: utf-8 -*-2import wave3import numpy as np4from pyaudio import PyAudio, paInt165class RecordUtil:6 NUM_SAMPLES = 2000 # pyaudioå
ç½®ç¼å²å¤§å°7 SAMPLING_RATE = 8000 # åæ ·é¢ç8 LEVEL = 500 # 声é³ä¿åçéå¼9 COUNT_NUM = 20 # NUM_SAMPLESä¸ªåæ ·ä¹å
åºç°COUNT_NUM个大äºLEVELçåæ ·åè®°å½å£°é³10 SAVE_LENGTH = 8 # 声é³è®°å½çæå°é¿åº¦ï¼SAVE_LENGTH * NUM_SAMPLES ä¸ªåæ ·11 TIME_COUNT = 16 # å½é³æ¶é´ï¼åä½s12 Voice_String = []13 def savewav(self, filename):14 wf = wave.open(filename, 'wb')15 wf.setnchannels(1)16 wf.setsampwidth(2)17 wf.setframerate(self.SAMPLING_RATE)18 wf.writeframes(np.array(self.Voice_String).tostring())19 # wf.writeframes(self.Voice_String.decode())20 wf.close()21 def recoder(self):22 pa = PyAudio()23 stream = pa.open(format=paInt16, channels=1, rate=self.SAMPLING_RATE, input=True,24 frames_per_buffer=self.NUM_SAMPLES)25 save_count = 026 save_buffer = []27 time_count = self.TIME_COUNT28 while True:29 time_count -= 130 # print time_count31 # 读å
¥NUM_SAMPLESä¸ªåæ ·32 string_audio_data = stream.read(self.NUM_SAMPLES)33 # å°è¯»å
¥çæ°æ®è½¬æ¢ä¸ºæ°ç»34 audio_data = np.fromstring(string_audio_data, dtype=np.short)35 # 计ç®å¤§äºLEVELçåæ ·ç个æ°36 large_sample_count = np.sum(audio_data > self.LEVEL)37 print('æ£å¨å½é³...')38 # print(np.max(audio_data))39 # å¦æä¸ªæ°å¤§äºCOUNT_NUMï¼åè³å°ä¿åSAVE_LENGTH个å40 if large_sample_count > self.COUNT_NUM:41 save_count = self.SAVE_LENGTH42 else:43 save_count -= 144 if save_count < 0:45 save_count = 046 if save_count > 0:47 # å°è¦ä¿åçæ°æ®åæ¾å°save_bufferä¸48 # print save_count > 0 and time_count >049 save_buffer.append(string_audio_data)50 else:51 # print save_buffer52 # å°save_bufferä¸çæ°æ®åå
¥WAVæä»¶ï¼WAVæä»¶çæä»¶åæ¯ä¿åçæ¶å»53 # print "debug"54 if len(save_buffer) > 0:55 self.Voice_String = save_buffer56 save_buffer = []57 print("Recode a piece of voice successfully!")58 return True59 if time_count == 0:60 if len(save_buffer) > 0:61 self.Voice_String = save_buffer62 save_buffer = []63 print("Recode a piece of voice successfully!")64 return True65 else:66 return False67if __name__ == "__main__":68 r = RecordUtil()69 r.recoder()...
pyaudio.py
Source: pyaudio.py
1# -*- coding: utf-8 -*-2import pyaudio3import numpy as np 4from datetime import datetime 5import wave6class recoder:7 NUM_SAMPLES = 2000 #pyaudioå
ç½®ç¼å²å¤§å°8 SAMPLING_RATE = 8000 #åæ ·é¢ç9 LEVEL = 500 #声é³ä¿åçéå¼10 COUNT_NUM = 20 #NUM_SAMPLESä¸ªåæ ·ä¹å
åºç°COUNT_NUM个大äºLEVELçåæ ·åè®°å½å£°é³11 SAVE_LENGTH = 8 #声é³è®°å½çæå°é¿åº¦ï¼SAVE_LENGTH * NUM_SAMPLES ä¸ªåæ ·12 TIME_COUNT = 60 #å½é³æ¶é´ï¼åä½s13 Voice_String = []14 def savewav(self,filename):15 wf = wave.open(filename, 'wb') 16 wf.setnchannels(1) 17 wf.setsampwidth(2) 18 wf.setframerate(self.SAMPLING_RATE) 19 wf.writeframes(np.array(self.Voice_String).tostring()) 20 # wf.writeframes(self.Voice_String.decode())21 wf.close() 22 def recoder(self):23 pa = pyaudio.PyAudio() 24 stream = pa.open(format=paInt16, channels=1, rate=self.SAMPLING_RATE, input=True, 25 frames_per_buffer=self.NUM_SAMPLES) 26 save_count = 0 27 save_buffer = [] 28 time_count = self.TIME_COUNT29 while True:30 time_count -= 131 # print time_count32 # 读å
¥NUM_SAMPLESä¸ªåæ ·33 string_audio_data = stream.read(self.NUM_SAMPLES) 34 # å°è¯»å
¥çæ°æ®è½¬æ¢ä¸ºæ°ç»35 audio_data = np.fromstring(string_audio_data, dtype=np.short)36 # 计ç®å¤§äºLEVELçåæ ·ç个æ°37 large_sample_count = np.sum( audio_data > self.LEVEL )38 print(np.max(audio_data))39 # å¦æä¸ªæ°å¤§äºCOUNT_NUMï¼åè³å°ä¿åSAVE_LENGTH个å40 if large_sample_count > self.COUNT_NUM:41 save_count = self.SAVE_LENGTH 42 else: 43 save_count -= 144 if save_count < 0:45 save_count = 0 46 if save_count > 0 : 47 # å°è¦ä¿åçæ°æ®åæ¾å°save_bufferä¸48 #print save_count > 0 and time_count >049 save_buffer.append( string_audio_data ) 50 else: 51 #print save_buffer52 # å°save_bufferä¸çæ°æ®åå
¥WAVæä»¶ï¼WAVæä»¶çæä»¶åæ¯ä¿åçæ¶å»53 #print "debug"54 if len(save_buffer) > 0 : 55 self.Voice_String = save_buffer56 save_buffer = [] 57 print("Recode a piece of voice successfully!")58 return True59 if time_count==0: 60 if len(save_buffer)>0:61 self.Voice_String = save_buffer62 save_buffer = [] 63 print("Recode a piece of voice successfully!")64 return True65 else:66 return False67if __name__ == "__main__":68 r = recoder()69 r.recoder()...
add_draconian_flags.py
Source: add_draconian_flags.py
1import dq11s.save2import sys3import struct45DRACONIAN_FLAG_IDENTIFIER = "DLC_00".encode()6DRACONIAN_FLAG_OFFSET_FROM_IDENTIFIER = -0x307DRACONIAN_FLAG_STRUCT = struct.Struct('<IIIIIIII')8DRACONIAN_FLAGS_TO_ADD = [9 1, # flag 010 1, # flag 111 1, # flag 212 1, # flag 313 1, # flag 414 1, # flag 515 1, # flag 616 1, # flag 717]1819if __name__ == "__main__":20 save_path = sys.argv[1]2122 with open(save_path, 'rb') as save_file:23 save_buffer = save_file.read()2425 save_is_encrypted, save_version = dq11s.save.get_save_is_encrypted_and_version(save_buffer)2627 if save_is_encrypted is None:28 print("file not recognized")29 exit(-1)3031 if save_is_encrypted:32 save_buffer, is_verified = dq11s.save.get_save_decrypt(save_buffer, save_version)33 if not is_verified:34 print("failed to verify save decryption")35 exit(-2)3637 draconian_identifier_offset = save_buffer.find(DRACONIAN_FLAG_IDENTIFIER)38 if draconian_identifier_offset == -1:39 print("failed to find flag location")40 exit(-3)4142 draconian_offset = draconian_identifier_offset + DRACONIAN_FLAG_OFFSET_FROM_IDENTIFIER4344 save_buffer = save_buffer[:draconian_offset] + DRACONIAN_FLAG_STRUCT.pack(*DRACONIAN_FLAGS_TO_ADD) \45 + save_buffer[draconian_offset + DRACONIAN_FLAG_STRUCT.size:]4647 with open(save_path, 'wb') as out_file:48 out_file.write(dq11s.save.get_save_encrypt(save_buffer, save_version))49
...
Check out the latest blogs from LambdaTest on this topic:
The best agile teams are built from people who work together as one unit, where each team member has both the technical and the personal skills to allow the team to become self-organized, cross-functional, and self-motivated. These are all big words that I hear in almost every agile project. Still, the criteria to make a fantastic agile team are practically impossible to achieve without one major factor: motivation towards a common goal.
Hey LambdaTesters! We’ve got something special for you this week. ????
Xamarin is an open-source framework that offers cross-platform application development using the C# programming language. It helps to simplify your overall development and management of cross-platform software applications.
As everyone knows, the mobile industry has taken over the world and is the fastest emerging industry in terms of technology and business. It is possible to do all the tasks using a mobile phone, for which earlier we had to use a computer. According to Statista, in 2021, smartphone vendors sold around 1.43 billion smartphones worldwide. The smartphone penetration rate has been continuously rising, reaching 78.05 percent in 2020. By 2025, it is expected that almost 87 percent of all mobile users in the United States will own a smartphone.
The sky’s the limit (and even beyond that) when you want to run test automation. Technology has developed so much that you can reduce time and stay more productive than you used to 10 years ago. You needn’t put up with the limitations brought to you by Selenium if that’s your go-to automation testing tool. Instead, you can pick from various test automation frameworks and tools to write effective test cases and run them successfully.
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!!