gokart5 / hello-world

0 stars 0 forks source link

ReSpeaker 4mic array LED help #1

Open gokart5 opened 5 years ago

gokart5 commented 5 years ago

Hello,

On my raspberry Pi, I want to make my ReSpeaker 4 mic array be able to turn on and off in idle whenever I want to, so with very few lines of code(preferably), and often. How would I be able to write a command for the lights to come on, and then another command to turn them off. I don't want to follow the snowball or Alexa or the other google home methods while doing this though. I would like my own method, having different colours and them moving around would be great but is not necessarily needed. So far all I have done is get them to turn on with a command in terminal and do a little demonstration. So any help for making the lights turn on with the simplest command would be greatly appreciated.

gokart5 commented 5 years ago

Heres some extra information to help. Could I possibly make a function that turned it on so I could call it when I needed it.

Heres my code for my project: while True: user_input = listenPY.listen(mode='google',) if user_input == "hello": print("Hello!") engine.say("hello") engine.runAndWait()

So basically, it just runs on if statements. If you say this, do this. But every time I talk I want the lights to turn on and then turn back off when I stop talking. What would the code be to get it to do this no matter how simple or hard.

I have got it to turn on, but only in terminal with the command after quite a few others commands before it: (env) pi@raspberrypi:~/4mics_hat $ python pixels_demo.py

Please help, I really want to get this working, is it possible to write a function to turn it on? Any suggestions are MUCH appreciated! Is this even possible, without following the websites version of getting it working which looks like this:

import pyaudio import wave import numpy as np

RESPEAKER_RATE = 16000 RESPEAKER_CHANNELS = 4 RESPEAKER_WIDTH = 2

run getDeviceInfo.py to get index

RESPEAKER_INDEX = 2 # refer to input device id CHUNK = 1024 RECORD_SECONDS = 3 WAVE_OUTPUT_FILENAME = "output.wav"

p = pyaudio.PyAudio()

stream = p.open( rate=RESPEAKER_RATE, format=p.get_format_from_width(RESPEAKER_WIDTH), channels=RESPEAKER_CHANNELS, input=True, input_device_index=RESPEAKER_INDEX,)

print("* recording")

frames = []

for i in range(0, int(RESPEAKER_RATE / CHUNK * RECORD_SECONDS)): data = stream.read(CHUNK)

extract channel 0 data from 4 channels, if you want to extract channel 1, please change to [1::4]

a = np.fromstring(data,dtype=np.int16)[0::4]
frames.append(a.tostring())

print("* done recording")

stream.stop_stream() stream.close() p.terminate()

wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb') wf.setnchannels(1) wf.setsampwidth(p.get_sample_size(p.get_format_from_width(RESPEAKER_WIDTH))) wf.setframerate(RESPEAKER_RATE) wf.writeframes(b''.join(frames)) wf.close()