Wireless Acoustic Sensor Networks (WASNs) consist of multiple devices which share their microphone recordings using a wireless channel such as WiFi. Such devices may be notebooks, cell phones, voice assistants, hearing aids, etc.
The goal of transmitting acoustic information over a network is to create network-connected microphone arrays, which allows for tasks such as source localization and beamforming to be performed.
The goal of this project is to provide a simple way for devices to share their microphone recordings over wireless networks. This is achieved using the Message Queue Telemetry Transport (MQTT) protocol, an established protocol for Internet-of-Things (IoT) applications. MQTT revolves around the message broker, a server responsible for transferring messages between devices. In WASN terminology, the message broker may be viewed as a fusion centre, although a distributed architecture is possible by instantiating one message broker in each connected device.
A second key concept in the MQTT protocol is the publisher-subscriber paradigm. In MQTT, a message is not sent to a receiver directly. Instead, the publisher sends the message to the broker along with a "topic name". In turn, interested devices must subscribe to the aforementioned topic. Finally, the broker will take care of automatically relaying the messages to the interested parties.
- Clone this repository using
git clone https://github.com/egrinstein/swan.git
- Enter the cloned directory using
cd swan
- Install most of the required Python libraries using
pip install -r requirements.txt
- Install the PyAudio library for your Python distribution
- A quick way of seeing what your distribution is by typing
python
in your terminal - Download the .whl file corresponding to your distribution from this website.
- Install the PyAudio library by running
pip install path/to/pyaudio.whl
- A quick way of seeing what your distribution is by typing
At least one of the devices in the network must be running an MQTT server/broker, which will receive and distribute the microphone signals from all devices. Installation steps for the Mosquitto broker are detailed below:
- MQTT uses port 1883 as default for communicating. This port must be therefore opened. On Windows, this is achieved by creating an "Inbound Port Rule" and an "Outbound Port Rule" in the firewall settings. See https://www.youtube.com/watch?v=IDMMzxDV4PQ&ab_channel=delightnet for a quick walkthrough.
- Install the Mosquitto MQTT message broker using the corresponding executable for your machine.
- Mosquitto is initially configured not to allow external connections. Before starting the server, we must change this behaviour. In the directory where you installed Mosquitto (in Windows, it is usually C:\Program Files\mosquitto), add the following lines to the file
mosquitto.conf
:
listener 1883
allow_anonymous true
- Finally, you may install Mosquitto as a Windows service by executing
mosquitto install
from Mosquitto's installation directory.
At least one of the machines in the network must host an MQTT server. In Windows, this may be achieved by opening a Powershell prompt as admin and executing net start mosquitto
- Running
python client.py
will start a swan client which will send signals to the network as well as receive signals from other devices.
- If connecting to a remote broker, run
python client.py network.broker_address=X.X.X.X
whereX.X.X.X
corresponds to the broker address you would like to connect to. Tip: use the commandsipconfig
(Windows) andifconfig
(Linux) to see what is your IP. - If you want the device only to publish its signals, set the flag
subscribe=false
. Conversely, set the flagpublish=false
only to listen to the signals within the network. - To see all available options, run
python client.py --help
.
- To stop the client, use Ctrl+C. You will be able to see the recorded signals in the
outputs/
directory, as well as stats on the received signals.
Run the unit tests with pytest tests/
The diagram below describes the code's architecture:
Here is a summary on how new audio features can be implemented:
-
Create a new function implementing the feature on
feature_manager.py
. The function should have one parameter as input, which is a MxN matrix of signals, where M is the number of channels in the device and N is the size of the signal -
Call the function within the
update
function of theFeatureManager
class, just like it is being done by themsc
function. -
Now move to
plotter.py
, where you should create a method that updates the feature when new data is received. Look at_update_msc
for a template -
Call the method you created on the update method under
Plotter
.def update_nf(x): N_SAMPLES_TO_USE = 4096 x = x[-N_SAMPLES_TO_USE:].astype(np.float32) / 32767.0 return (np.square(x).sum() + noise_floor) / 2
noise_floor = update_nf(signal)