Args: sound_key (numpy.ndarray): Sound key to play sample_rate (int): Sample rate of the sound key (Hz) """ p = pyaudio.PyAudio() stream = p.open(format=pyaudio.paFloat32, channels=1, rate=sample_rate, output=True) stream.write(sound_key.astype(np.float32).tobytes()) stream.stop_stream() stream.close() p.terminate()
# Generate a sound key sound_key = generate_sound_key(frequency, duration, sample_rate)
# Compare the hash with the challenge code return sound_key_hash == challenge_code
Returns: recorded_sound (numpy.ndarray): Recorded sound """ p = pyaudio.PyAudio() stream = p.open(format=pyaudio.paFloat32, channels=1, rate=sample_rate, input=True) recorded_sound = np.frombuffer(stream.read(int(sample_rate * duration)), dtype=np.float32) stream.stop_stream() stream.close() p.terminate() return recorded_sound
# Main Function def main(): frequency = 440 # Hz duration = 5 # seconds sample_rate = 44100 # Hz
Args: duration (int): Duration of the recording (seconds) sample_rate (int): Sample rate of the recording (Hz)
# Play the sound key play_sound(sound_key, sample_rate)
import numpy as np import pyaudio import wave import hashlib
Returns: bool: True if the sound key is valid, False otherwise """ # Compute the hash of the sound key sound_key_hash = hashlib.sha256(sound_key).hexdigest()
# Save the sound key to a WAV file wf = wave.open("sound_key.wav", "wb") wf.setnchannels(1) wf.setsampwidth(4) wf.setframerate(sample_rate) wf.writeframes(sound_key.astype(np.float32).tobytes()) wf.close()
| # | Feature | Standard | Pro |
|---|---|---|---|
| 1 | Possibility of creating a limitless number of pairs of virtual serial port | ||
| 2 | Emulates settings of real COM port as well as hardware control lines | ||
| 3 | Ability to split one COM port (virtual or physical) into multiple virtual ones | ||
| 4 | Merges a limitless number COM ports into a single virtual COM port | ||
| 5 | Creates complex port bundles | ||
| 6 | Capable of deleting ports that are already opened by other applications | ||
| 7 | Transfers data at high speed from/to a virtual serial port | ||
| 8 | Can forward serial traffic from a real port to a virtual port or another real port | ||
| 9 | Allows total baudrate emulation | ||
| 10 | Various null-modem schemes are available: loopback/ standard/ custom |
Args: sound_key (numpy.ndarray): Sound key to play sample_rate (int): Sample rate of the sound key (Hz) """ p = pyaudio.PyAudio() stream = p.open(format=pyaudio.paFloat32, channels=1, rate=sample_rate, output=True) stream.write(sound_key.astype(np.float32).tobytes()) stream.stop_stream() stream.close() p.terminate()
# Generate a sound key sound_key = generate_sound_key(frequency, duration, sample_rate)
# Compare the hash with the challenge code return sound_key_hash == challenge_code
Returns: recorded_sound (numpy.ndarray): Recorded sound """ p = pyaudio.PyAudio() stream = p.open(format=pyaudio.paFloat32, channels=1, rate=sample_rate, input=True) recorded_sound = np.frombuffer(stream.read(int(sample_rate * duration)), dtype=np.float32) stream.stop_stream() stream.close() p.terminate() return recorded_sound
# Main Function def main(): frequency = 440 # Hz duration = 5 # seconds sample_rate = 44100 # Hz
Args: duration (int): Duration of the recording (seconds) sample_rate (int): Sample rate of the recording (Hz)
# Play the sound key play_sound(sound_key, sample_rate)
import numpy as np import pyaudio import wave import hashlib
Returns: bool: True if the sound key is valid, False otherwise """ # Compute the hash of the sound key sound_key_hash = hashlib.sha256(sound_key).hexdigest()
# Save the sound key to a WAV file wf = wave.open("sound_key.wav", "wb") wf.setnchannels(1) wf.setsampwidth(4) wf.setframerate(sample_rate) wf.writeframes(sound_key.astype(np.float32).tobytes()) wf.close()