├── README.md ├── audio-poc ├── get-cards-and-devices.py └── record-audio.py ├── requirements.txt ├── Fingerprint ├── example_downloadimage.py ├── fingerprint_test.py ├── example_search.py └── example_enroll.py └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # raspi-fingerprint-audio-conversation -------------------------------------------------------------------------------- /audio-poc/get-cards-and-devices.py: -------------------------------------------------------------------------------- 1 | import pyaudio 2 | p = pyaudio.PyAudio() 3 | for ii in range(p.get_device_count()): 4 | print(ii) 5 | print(p.get_device_info_by_index(ii).get('name')) -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Cython==0.29.28 2 | numpy==1.21.5 3 | opencv-python==4.5.5.64 4 | Pillow==9.0.1 5 | pyserial==3.5 6 | torch @ file:///home/pi/Desktop/torch-1.8.0a0%2B56b43f4-cp37-cp37m-linux_armv7l.whl 7 | torchvision @ file:///home/pi/Desktop/torchvision-0.9.0a0%2B8fb5838-cp37-cp37m-linux_armv7l.whl 8 | typing_extensions==4.1.1 9 | -------------------------------------------------------------------------------- /audio-poc/record-audio.py: -------------------------------------------------------------------------------- 1 | import pyaudio 2 | import wave 3 | 4 | form_1 = pyaudio.paInt16 # 16-bit resolution 5 | chans = 1 # 1 channel 6 | samp_rate = 16000 # 44.1kHz sampling rate 7 | chunk = 4096 # 2^12 samples for buffer 8 | record_secs = 3 # seconds to record 9 | dev_index = 1 # device index found by p.get_device_info_by_index(ii) 10 | wav_output_filename = 'test1.wav' # name of .wav file 11 | 12 | audio = pyaudio.PyAudio() # create pyaudio instantiation 13 | 14 | # create pyaudio stream 15 | stream = audio.open(format = form_1,rate = samp_rate,channels = chans, \ 16 | input_device_index = dev_index,input = True, \ 17 | frames_per_buffer=chunk) 18 | print("recording") 19 | frames = [] 20 | 21 | # loop through stream and append audio chunks to frame array 22 | for ii in range(0,int((samp_rate/chunk)*record_secs)): 23 | data = stream.read(chunk) 24 | frames.append(data) 25 | 26 | print("finished recording") 27 | 28 | # stop the stream, close it, and terminate the pyaudio instantiation 29 | stream.stop_stream() 30 | stream.close() 31 | audio.terminate() 32 | 33 | # save the audio frames as .wav file 34 | wavefile = wave.open(wav_output_filename,'wb') 35 | wavefile.setnchannels(chans) 36 | wavefile.setsampwidth(audio.get_sample_size(form_1)) 37 | wavefile.setframerate(samp_rate) 38 | wavefile.writeframes(b''.join(frames)) 39 | wavefile.close() -------------------------------------------------------------------------------- /Fingerprint/example_downloadimage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | PyFingerprint 6 | Copyright (C) 2015 Bastian Raschke 7 | All rights reserved. 8 | 9 | """ 10 | 11 | import tempfile 12 | from pyfingerprint.pyfingerprint import PyFingerprint 13 | import os 14 | 15 | 16 | filepath = "/home/pi/Desktop/fingerprint_scan/" 17 | 18 | ## Reads image and download it 19 | ## 20 | 21 | ## Tries to initialize the sensor 22 | try: 23 | f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) 24 | 25 | if ( f.verifyPassword() == False ): 26 | raise ValueError('The given fingerprint sensor password is wrong!') 27 | 28 | except Exception as e: 29 | print('The fingerprint sensor could not be initialized!') 30 | print('Exception message: ' + str(e)) 31 | exit(1) 32 | 33 | ## Gets some sensor information 34 | print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity())) 35 | 36 | ## Tries to read image and download it 37 | try: 38 | print('Waiting for finger...') 39 | 40 | ## Wait that finger is read 41 | while ( f.readImage() == False ): 42 | pass 43 | 44 | print('Downloading image (this take a while)...') 45 | 46 | #imageDestination = tempfile.gettempdir() + '/fingerprint.bmp' 47 | imageDestination = os.path.join(filepath, "fingerprint.bmp") 48 | f.downloadImage(imageDestination) 49 | 50 | print('The image was saved to "' + imageDestination + '".') 51 | 52 | except Exception as e: 53 | print('Operation failed!') 54 | print('Exception message: ' + str(e)) 55 | exit(1) 56 | -------------------------------------------------------------------------------- /Fingerprint/fingerprint_test.py: -------------------------------------------------------------------------------- 1 | import time 2 | from pyfingerprint.pyfingerprint import PyFingerprint 3 | from pyfingerprint.pyfingerprint import FINGERPRINT_CHARBUFFER1 4 | from pyfingerprint.pyfingerprint import FINGERPRINT_CHARBUFFER2 5 | 6 | ## Enrolls new finger 7 | ## 8 | 9 | ## Tries to initialize the sensor 10 | try: 11 | f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) 12 | print("1. > sensor initialized") 13 | if ( f.verifyPassword() == False ): 14 | raise ValueError('The given fingerprint sensor password is wrong!') 15 | 16 | except Exception as e: 17 | print('The fingerprint sensor could not be initialized!') 18 | print('Exception message: ' + str(e)) 19 | exit(1) 20 | 21 | ## Gets some sensor information 22 | #print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity())) 23 | 24 | ## Wait that finger is read 25 | while ( f.readImage() == False ): 26 | pass 27 | 28 | f.convertImage(FINGERPRINT_CHARBUFFER1) 29 | 30 | result = f.searchTemplate() 31 | positionNumber = result[0] 32 | if ( positionNumber >= 0 ): 33 | print('Template already exists at position #' + str(positionNumber)) 34 | 35 | print('Remove finger...') 36 | time.sleep(2) 37 | 38 | print('Waiting for same finger again...') 39 | 40 | ## Wait that finger is read again 41 | while ( f.readImage() == False ): 42 | pass 43 | 44 | ## Converts read image to characteristics and stores it in charbuffer 2 45 | f.convertImage(FINGERPRINT_CHARBUFFER2) 46 | 47 | ## Compares the charbuffers 48 | if ( f.compareCharacteristics() == 0 ): 49 | raise Exception('Fingers do not match') 50 | print(f.downloadCharacteristics(FINGERPRINT_CHARBUFFER1) == (f.downloadCharacteristics(FINGERPRINT_CHARBUFFER2))) 51 | 52 | 53 | -------------------------------------------------------------------------------- /Fingerprint/example_search.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | PyFingerprint 6 | Copyright (C) 2015 Bastian Raschke 7 | All rights reserved. 8 | 9 | """ 10 | 11 | import hashlib 12 | from pyfingerprint.pyfingerprint import PyFingerprint 13 | from pyfingerprint.pyfingerprint import FINGERPRINT_CHARBUFFER1 14 | 15 | 16 | ## Search for a finger 17 | ## 18 | 19 | ## Tries to initialize the sensor 20 | try: 21 | f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) 22 | 23 | if ( f.verifyPassword() == False ): 24 | raise ValueError('The given fingerprint sensor password is wrong!') 25 | 26 | except Exception as e: 27 | print('The fingerprint sensor could not be initialized!') 28 | print('Exception message: ' + str(e)) 29 | exit(1) 30 | 31 | ## Gets some sensor information 32 | print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity())) 33 | 34 | ## Tries to search the finger and calculate hash 35 | try: 36 | print('Waiting for finger...') 37 | 38 | ## Wait that finger is read 39 | while ( f.readImage() == False ): 40 | pass 41 | 42 | ## Converts read image to characteristics and stores it in charbuffer 1 43 | f.convertImage(FINGERPRINT_CHARBUFFER1) 44 | 45 | ## Searchs template 46 | result = f.searchTemplate() 47 | 48 | positionNumber = result[0] 49 | accuracyScore = result[1] 50 | 51 | if ( positionNumber == -1 ): 52 | print('No match found!') 53 | exit(0) 54 | else: 55 | print('Found template at position #' + str(positionNumber)) 56 | print('The accuracy score is: ' + str(accuracyScore)) 57 | 58 | ## OPTIONAL stuff 59 | ## 60 | 61 | ## Loads the found template to charbuffer 1 62 | f.loadTemplate(positionNumber, FINGERPRINT_CHARBUFFER1) 63 | 64 | ## Downloads the characteristics of template loaded in charbuffer 1 65 | characterics = str(f.downloadCharacteristics(FINGERPRINT_CHARBUFFER1)).encode('utf-8') 66 | print("--->", characterics) 67 | 68 | ## Hashes characteristics of template 69 | print('SHA-2 hash of template: ' + hashlib.sha256(characterics).hexdigest()) 70 | 71 | except Exception as e: 72 | print('Operation failed!') 73 | print('Exception message: ' + str(e)) 74 | exit(1) 75 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | **/**.wav 131 | **.png 132 | -------------------------------------------------------------------------------- /Fingerprint/example_enroll.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | PyFingerprint 6 | Copyright (C) 2015 Bastian Raschke 7 | All rights reserved. 8 | 9 | """ 10 | 11 | import time 12 | from pyfingerprint.pyfingerprint import PyFingerprint 13 | from pyfingerprint.pyfingerprint import FINGERPRINT_CHARBUFFER1 14 | from pyfingerprint.pyfingerprint import FINGERPRINT_CHARBUFFER2 15 | 16 | 17 | ## Enrolls new finger 18 | ## 19 | 20 | ## Tries to initialize the sensor 21 | try: 22 | f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) 23 | print("1. > sensor initialized") 24 | if ( f.verifyPassword() == False ): 25 | raise ValueError('The given fingerprint sensor password is wrong!') 26 | 27 | except Exception as e: 28 | print('The fingerprint sensor could not be initialized!') 29 | print('Exception message: ' + str(e)) 30 | exit(1) 31 | 32 | ## Gets some sensor information 33 | print('2. Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity())) 34 | 35 | ## Tries to enroll new finger 36 | try: 37 | print('3. Waiting for finger...') 38 | 39 | ## Wait that finger is read 40 | while ( f.readImage() == False ): 41 | pass 42 | 43 | ## Converts read image to characteristics and stores it in charbuffer 1 44 | f.convertImage(FINGERPRINT_CHARBUFFER1) 45 | 46 | ## Checks if finger is already enrolled 47 | result = f.searchTemplate() 48 | 49 | positionNumber = result[0] 50 | print("----->", result) 51 | if ( positionNumber >= 0 ): 52 | print('Template already exists at position #' + str(positionNumber)) 53 | exit(0) 54 | 55 | print('Remove finger...') 56 | time.sleep(2) 57 | 58 | print('Waiting for same finger again...') 59 | 60 | ## Wait that finger is read again 61 | while ( f.readImage() == False ): 62 | pass 63 | 64 | ## Converts read image to characteristics and stores it in charbuffer 2 65 | f.convertImage(FINGERPRINT_CHARBUFFER2) 66 | 67 | ## Compares the charbuffers 68 | if ( f.compareCharacteristics() == 0 ): 69 | raise Exception('Fingers do not match') 70 | 71 | ## Creates a template 72 | f.createTemplate() 73 | 74 | ## Saves template at new position number 75 | positionNumber = f.storeTemplate() 76 | print('Finger enrolled successfully!') 77 | print('New template position #' + str(positionNumber)) 78 | 79 | except Exception as e: 80 | print('Operation failed!') 81 | print('Exception message: ' + str(e)) 82 | exit(1) 83 | --------------------------------------------------------------------------------