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:
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.
Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.
Mobile application development is on the rise like never before, and it proportionally invites the need to perform thorough testing with the right mobile testing strategies. The strategies majorly involve the usage of various mobile automation testing tools. Mobile testing tools help businesses automate their application testing and cut down the extra cost, time, and chances of human error.
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!!