Advertisement
j0h

noteScan

j0h
Jul 7th, 2025 (edited)
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import simpleaudio as sa
  3. import numpy as np
  4. # sudo apt-get install -y python3-dev libasound2-dev
  5. '''
  6. # honeywell 1300g-2-06211
  7. manual: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/ppr/ja/public/products/barcode-scanners/general-purpose-handheld/1300g/documents/sps-ppr-hp1300-ug.pdf?download=false
  8. page 45 turns off beep sound
  9. '''
  10.  
  11. notes = {
  12.     "C": 261.63,
  13.     "C#": 277.18,
  14.     "D": 293.66,
  15.     "D#": 311.13,
  16.     "E": 329.63,
  17.     "F": 349.23,
  18.     "F#": 369.99,
  19.     "G": 392.00,
  20.     "G#": 415.30,
  21.     "A": 440.00,
  22.     "A#": 466.16,
  23.     "B": 493.88
  24. }
  25.  
  26. def play_note(freq, duration=0.5):
  27.     fs = 44100  # sampling rate: "Weird sample rates are not supported."
  28.     vol = 32767 # volume
  29.     bpS = 2     # bits per Sample 1-4
  30.     ch = 1      # channels
  31.     t = np.linspace(0, duration, int(fs * duration), False)
  32.     wave = 0.5 * np.cos(2 * np.pi * freq * t)
  33.     audio = (wave * 64000).astype(np.int16)
  34.     sa.play_buffer(audio, ch, bpS, fs).wait_done()
  35.  
  36. print("Scan a note (C, D#, F#, etc.):")
  37. try:
  38.     while True:
  39.         scanned = input().strip().upper()
  40.         if scanned in notes:
  41.             play_note(notes[scanned])
  42.         else:
  43.             print(f"Unknown note: {scanned}")
  44. except KeyboardInterrupt:
  45.     print("Exiting.")
  46.  
  47. ''' row your boat
  48. C   C   C   D   E
  49. E   D   E   F   G
  50. C   C   C   G   G
  51. G   E   E   E   C
  52. C   C   D   E   F
  53. E   C   G   G   C
  54.  
  55. '''
  56.  
  57. '''
  58. next episode Dr Dre
  59. G   B   C   G  
  60. B   C   G   B  
  61. C   G   B   C
  62.  
  63. '''
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement