Golang GRPC stream server and client for sending audio and video.
This is a demonstration of a bi-directional GRPC stream, while also being somewhat interesting in that it is streaming audio and images with the connected microphone and webcam. I have so far only tested on a Macbook Pro. While the following installation instructions are for OSX as well, there is no reason this wouldn't work on other OS's with the proper gocv and portaudio installations.
I would eventually like to target running on a Raspberry Pi with an attached display, webcam, and microphone. Otherwise, I hope to learn a bit about:
- GRPC Streams
- Golang Threading
- Audio/Video
-
Install Opencv
brew install opencv
Install pk-config if not already installed
brew install pkg-config
be sure to have pkg-config var set correctly
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
Opencv comes with it's own .pc, move it or simlink it to the PKG_CONFIG_PATH
ln -s /usr/local/opt/opencv@4/lib/pkgconfig/opencv4.pc $PKG_CONFIG_PATH
Add these lines to your environment
.bash_profile
or similiarexport PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ alias opencvflags="pkg-config --cflags --libs opencv"
-
Install PortAudio
brew install portaudio
Using protobuf and protoc for code-generation of go files (i.e. intercom.pb.go
)
To generate updated proto files, run:
cd _proto
protoc \
-I ./ \
--go_out=plugins=grpc:../proto \
intercom.proto
-
Start Server
cd cmd/server go run main.go
-
Start Client
cd cmd/client go run main.go 0 [path to background image, hopefully a kitten]
Press [Spacebar] to broadcast
Press [Esc] to exit
Note that feedback can occur. Once multiple clients are supported this can be addressed.