Python 3 neopixel non-functional - python-3.x

import neopixel
import board
import sounddevice as sd
from numpy import linalg as LA
import numpy as np
def getvolume(indata, outdata, frames, time, status):
volume_norm = np.linalg.norm(indata)*10
with sd.Stream(callback=getvolume):
sd.sleep(250)
pixels = neopixel.NeoPixel(board.D18, 144)
pixels.fill((volume_norm, volume_norm, volume_norm))`
I want the code to make the LED strip shine brighter the louder the sound is. It currently doesn't do anything. What am I doing wrong?

Related

How to get ˚ in openCV

I want to write ˚ (degree character) in my image. I'm using Python and OpenCV.
The character, however, is shown as ??. This is my code:
import numpy as np
import cv2
import matplotlib.pyplot as plt
read=np.ones((500,500))
temp=100
read=cv2.putText(read,'{:>8.2f} ℃'.format(temp),(20,100), font, 2,(255,255,255),4,cv2.LINE_AA)
plt.imshow(read)
This is the output:
Thanks you, eldesgraciado,
PIL works well
import numpy as np
import cv2
import matplotlib.pyplot as plt
from PIL import Image, ImageFont, ImageDraw
font_path = 'C:\Windows\Fonts\Arial.ttf'
font_size = 48
font = ImageFont.truetype(font_path, font_size)
read=np.ones((500,500))
temp=100
img=Image.fromarray(read)
draw=ImageDraw.Draw(img)
draw.text((0, 50),'{:>9.2f} ˚C'.format(temp), font=font, fill=255)
read=np.array(img)
plt.imshow(read)

numpy data sounds different than original sound_file.wav file

import wave
import numpy as np
from IPython.display import display, Audio
#sound 1
with wave.open('sound_file.wav', 'rb') as wf:
signal = np.frombuffer(wf.readframes(nframes = wf.getnframes()), 'int' + str(int(16 * wf.getsampwidth())))
display(Audio(data = signal, rate = wf.getframerate()))
#sound2
display(Audio('sound_file.wav'))
here the sound1 sounds different than sound2 so can anyone tell me what happens there.
As well as please state some usual practices of sound preprocessing that must be done after getting an np array from a sound file.

How to convert audio file to picture for every 0.1 seconds in python

I have an auido file of the engine. I would like to convert it into the spectrogram.
import matplotlib.pyplot as plot
from scipy import signal
from scipy.io import wavfile
from pydub import AudioSegment
samplingFrequency, signalData = wavfile.read('datamusic/car2.wav')
plot.subplot(111)
plot.specgram(signalData,Fs=samplingFrequency)
plot.savefig("datapicture/car2.png")
It is the code that o have found. However it converts all sound.

Live Screen Monitoring With Python3 Pytesseract

I am working on a python3 project on windows 10, and I was wondering if anyone knew of anyway to pass an opencv screen grab through pytesseract? If not, is there any other OCR that you could?
Here is the code for the opencv screen grab:
import numpy as np
from PIL import ImageGrab
import cv2
while True:
screen = np.array(ImageGrab.grab(bbox=(0,40,800,640)))
cv2.imshow('window', cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY))
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
I know very little about pytesseract, but this might get you started:
#!/usr/bin/env python3
import numpy as np
from PIL import ImageGrab
import pytesseract
from PIL import Image, ImageEnhance, ImageFilter
from textblob import TextBlob
# Grab some screen
screen = ImageGrab.grab(bbox=(0,0,800,640))
# Make greyscale
w = screen.convert('L')
# Save so we can see what we grabbed
w.save('grabbed.png')
text = pytesseract.image_to_string(w)
correctedText = TextBlob(text).correct()
print(correctedText)
From this grab:
I got:
# Terminal Shell Edit View Window Help
The writing is on the wall

Python exponential plot is wrong

I am new using python and try to do some plots. I realized, that a plot of a bump function is incorrect. I have no idea how python came to this result.
This is my 'code'
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
class MainBody():
x = np.linspace(0.0001,99.9999,1000)
result = np.exp((-1.0)/(x*(100.0-x)))
plt.plot(x,result)
plt.show()
I got this result
but I should get this
I know that Python is powerful but I think such simple things should work without occuring such errors, where is my mistake?
Thank you
Matthias
Use plt.ylim to set the y-limits. Otherwise, by default, matplotlib will try to show the entire dataset, whose y-limits go roughly from 0 to 1:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0.0001,99.9999,1000)
result = np.exp((-1.0)/(x*(100.0-x)))
plt.plot(x,result)
plt.ylim(0.9975, 0.9999)
plt.show()

Resources