Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [Help] Displaying image to screen based on "loudness"
New Posts  All Forums:Forum Nav:

[Help] Displaying image to screen based on "loudness"

post #1 of 2
Thread Starter 
Hi all,
A friend and I have been working on a project that involves the raspberry pi. We are trying to display an image to the screen based on how loud he is talking.
For example if he is below a certain volume threshold while speaking display an image, and if he gets too loud then change the image that is being displayed.
Here is a link to the post on stackoverflow https://stackoverflow.com/questions/43313771/audioop-error-displaying-image-based-on-microphone-level
Thank you for your time! thumb.gif
-Ray
Prometheus
(18 items)
 
  
CPUMotherboardGraphicsGraphics
i7 3820 gigabyte x79 ud3 evga 780 ti evga 780 ti 
RAMHard DriveHard DriveCooling
hyper x 16gb 256gb crucial m4 1tb WD noctua nh-d15 
OSMonitorMonitorKeyboard
windows 8.1 pro 64bit samsung ud590 asus vn24 x3 corsair k70 
PowerCaseMouseMouse Pad
cooler master v1000 nzxt h440 mionix naos 7000 Plexipad 
AudioOther
Hyper X Cloud Razer Deathadder 2013 
  hide details  
Reply
Prometheus
(18 items)
 
  
CPUMotherboardGraphicsGraphics
i7 3820 gigabyte x79 ud3 evga 780 ti evga 780 ti 
RAMHard DriveHard DriveCooling
hyper x 16gb 256gb crucial m4 1tb WD noctua nh-d15 
OSMonitorMonitorKeyboard
windows 8.1 pro 64bit samsung ud590 asus vn24 x3 corsair k70 
PowerCaseMouseMouse Pad
cooler master v1000 nzxt h440 mionix naos 7000 Plexipad 
AudioOther
Hyper X Cloud Razer Deathadder 2013 
  hide details  
Reply
post #2 of 2
From the web:

def _assamples(fragment, width):
if isinstance(fragment, str):
fragment = fragment.encode()
view = memoryview(fragment)
try:
format = _formats[width]
except KeyError:
raise error('Size should be 1, 2 or 4') from None
try:
return view.cast(format)
except TypeError:
if len(fragment) % width:
raise error('not a whole number of frames') from None
if not fragment: # cannot cast view with zeros in shape or strides
return memoryview(b'')
raise


Your error occurs with the length of the sample isn't divisible by your choice of width, which is 2 (the % is a modulus operator - google to learn more.) Considering I'm not good at coding, the first thing I would try is to force the remainder of sample / width to 0 using a crude filter right before passing it into the argument.
Overkill
(19 items)
 
  
CPUMotherboardGraphicsRAM
i7 5820k @ 4.625Ghz ASUS Rampage V Extreme GTX 1080 Ti 32GB G.Skill RIPJAWS 3200Mhz CL14 
Hard DriveHard DriveHard DriveHard Drive
Intel 750 400GB Samsung 850 Pro 512GB Samsung 850 EVO 500GB WD Black 4TB 7200RPM 
Hard DriveCoolingOSMonitor
Hitachi 2TB 7200RPM Corsair H80i GT Windows 10 Professional Acer Predator X34 3440x1440 100hz IPS 
KeyboardPowerCaseMouse
Razer BlackWidow Chroma Corsair RM1000i SilverStone RV02 Razer DeathAdder 3G 
AudioAudioAudio
TEAC HA-501 HRT Music Streamer II+ DAC Sennheiser HD650 
  hide details  
Reply
Overkill
(19 items)
 
  
CPUMotherboardGraphicsRAM
i7 5820k @ 4.625Ghz ASUS Rampage V Extreme GTX 1080 Ti 32GB G.Skill RIPJAWS 3200Mhz CL14 
Hard DriveHard DriveHard DriveHard Drive
Intel 750 400GB Samsung 850 Pro 512GB Samsung 850 EVO 500GB WD Black 4TB 7200RPM 
Hard DriveCoolingOSMonitor
Hitachi 2TB 7200RPM Corsair H80i GT Windows 10 Professional Acer Predator X34 3440x1440 100hz IPS 
KeyboardPowerCaseMouse
Razer BlackWidow Chroma Corsair RM1000i SilverStone RV02 Razer DeathAdder 3G 
AudioAudioAudio
TEAC HA-501 HRT Music Streamer II+ DAC Sennheiser HD650 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [Help] Displaying image to screen based on "loudness"