Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored the script to a real library.
Related to #9
- Loading branch information
1 parent
7a6925c
commit 6a63c75
Showing
24 changed files
with
954 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,42 @@ | ||
*.pyc | ||
|
||
test2.py | ||
test.py | ||
__pycache__/pyVBAN.cpython-37.pyc | ||
# Packages | ||
*.egg | ||
!/tests/**/*.egg | ||
/*.egg-info | ||
/dist/* | ||
dist | ||
build | ||
_build | ||
.cache | ||
*.so | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
||
# Unit test / coverage reports | ||
.coverage | ||
.pytest_cache | ||
|
||
.DS_Store | ||
.idea/* | ||
.python-version | ||
.vscode/* | ||
|
||
/test.py | ||
/test_*.* | ||
|
||
/setup.cfg | ||
MANIFEST.in | ||
/setup.py | ||
/docs/site/* | ||
/tests/fixtures/simple_project/setup.py | ||
/tests/fixtures/project_with_extras/setup.py | ||
.mypy_cache | ||
|
||
.venv | ||
/releases/* | ||
pip-wheel-metadata | ||
/poetry.toml | ||
|
||
poetry/core/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,128 @@ | ||
# pyVBAN | ||
python implementation of the VBAN (VB Audio network) protocol | ||
Specification here: https://www.vb-audio.com/Voicemeeter/VBANProtocol_Specifications.pdf | ||
The module supports audio receiving and transmitting + text transmitting | ||
|
||
## Requierments | ||
Need of the pyaudio module | ||
Python implementation of the VBAN (VB Audio network) protocol | ||
|
||
## pyVBAN.VBAN_Recv() usage: | ||
```python | ||
cl = VBAN_Recv("IP-FROM","StreamName",Port,OutputDeviceIndex,verbose=False) | ||
cl.runforever() | ||
``` | ||
Original specifications here: https://www.vb-audio.com/Voicemeeter/VBANProtocol_Specifications.pdf | ||
|
||
Example: | ||
```python | ||
cl = VBAN_Recv("127.0.0.1","Stream7",6981,10,verbose=False) | ||
cl.runforever() | ||
``` | ||
or | ||
Supported sub-protocols: | ||
- [x] Audio | ||
- [x] Serial **(To verify)** | ||
- [x] Text | ||
- [ ] Service | ||
|
||
As I'm currently not using VBAN nor VB-Audio products I have no plans to implement this further. | ||
I will do my best to maintain it! | ||
|
||
For any feature request, the specs are open, feel free to open a PR 😀 | ||
|
||
## Using the built-in utilities | ||
### List devices | ||
```bash | ||
$ python -m pyvban.utils.device_list | ||
``` | ||
```python | ||
cl = VBAN_Recv("127.0.0.1","Stream7",6981,10,verbose=False) | ||
while True: | ||
cl.runonce() | ||
import logging | ||
import pyvban | ||
logging.basicConfig(level=logging.DEBUG) | ||
pyvban.utils.device_list() | ||
``` | ||
|
||
## pyVBAN.VBAN_Send() usage: | ||
### Receiver | ||
```bash | ||
$ python -m pyvban.utils.receiver --address 127.0.0.1 --port 6980 --stream Stream1 --device 11 | ||
``` | ||
```python | ||
cl = VBAN_Send("IP-TO",PORT,"StreamName",SampleRate,DeviceInId,verbose=False) | ||
cl.runforever() | ||
import logging | ||
import pyvban | ||
logging.basicConfig(level=logging.DEBUG) | ||
receiver = pyvban.utils.VBAN_Receiver( | ||
sender_ip="127.0.0.1", | ||
stream_name="Stream1", | ||
port=6980, | ||
device_index=11 | ||
) | ||
receiver.run() | ||
``` | ||
|
||
Example: | ||
### Sender | ||
```bash | ||
$ python -m pyvban.utils.sender --address 127.0.0.1 --port 6980 --stream Stream1 --rate 48000 --channels 2 --device 1 | ||
``` | ||
```python | ||
cl = VBAN_Send("127.0.0.1",6980,"Stream8",48000,3,verbose=True) | ||
cl.runforever() | ||
import logging | ||
import pyvban | ||
logging.basicConfig(level=logging.DEBUG) | ||
sender = pyvban.utils.VBAN_Sender( | ||
receiver_ip="127.0.0.1", | ||
receiver_port=6980, | ||
stream_name="Stream1", | ||
sample_rate=48000, | ||
channels=2, | ||
device_index=1 | ||
) | ||
sender.run() | ||
``` | ||
or | ||
|
||
### Send text | ||
```bash | ||
$ python -m pyvban.utils.send_text --address 127.0.0.1 --port 6980 --stream Command1 "Strip[5].Mute = 0" | ||
``` | ||
```python | ||
cl = VBAN_Send("127.0.0.1",6980,"Stream8",48000,3,verbose=True) | ||
import logging | ||
import pyvban | ||
import time | ||
logging.basicConfig(level=logging.DEBUG) | ||
send_text = pyvban.utils.VBAN_SendText( | ||
receiver_ip="127.0.0.1", | ||
receiver_port=6980, | ||
stream_name="Command1" | ||
) | ||
state = False | ||
while True: | ||
cl.runonce() | ||
state = not state | ||
if state: | ||
send_text.send("Strip[5].Mute = 0") | ||
else: | ||
send_text.send("Strip[5].Mute = 1") | ||
time.sleep(1) | ||
``` | ||
|
||
## pyVBAN.VBAN_SendText() usage: | ||
```python | ||
cl = VBAN_SendText("IP-TO",PORT,BAUDRATE,"StreamName") | ||
cl.send("Command") | ||
``` | ||
|
||
Example: | ||
## Craft a packet manually | ||
|
||
```python | ||
cl = VBAN_SendText("127.0.0.1",6980,9600,"Command1") | ||
cl.send("Strip[0].Gain = -6") | ||
``` | ||
import pyvban | ||
|
||
## Help | ||
To find the output device index you can use this code: | ||
pcm_data = b"" # 128 sample stereo data | ||
header = pyvban.VBANAudioHeader( | ||
sample_rate=pyvban.subprotocols.audio.VBANSampleRates.RATE_48000, | ||
samples_per_frame=128, | ||
channels=2, | ||
format=pyvban.subprotocols.audio.VBANBitResolution.VBAN_BITFMT_16_INT, | ||
codec=pyvban.subprotocols.audio.VBANCodec.VBAN_CODEC_PCM, | ||
stream_name="Stream1", | ||
frame_counter=0, | ||
) | ||
|
||
```python | ||
import pyaudio | ||
p = pyaudio.PyAudio() | ||
info = p.get_host_api_info_by_index(0) | ||
numdevices = info.get('deviceCount') | ||
|
||
print("--- INPUT DEVICES ---") | ||
for i in range(0, numdevices): | ||
if (p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0: | ||
print("Input Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0, i).get('name')) | ||
|
||
print("--- OUTPUT DEVICES ---") | ||
for i in range(0, numdevices): | ||
if (p.get_device_info_by_host_api_device_index(0, i).get('maxOutputChannels')) > 0: | ||
print("Input Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0, i).get('name')) | ||
vban_packet = header.to_bytes() + pcm_data | ||
vban_packet = vban_packet[:pyvban.const.VBAN_PROTOCOL_MAX_SIZE] | ||
``` | ||
|
||
## Parse a packet manually | ||
```python | ||
import pyvban | ||
|
||
def run_once(self): | ||
data, addr = socket.recvfrom(pyvban.const.VBAN_PROTOCOL_MAX_SIZE) | ||
packet = pyvban.VBANPacket(data) | ||
if packet.header: | ||
if packet.header.sub_protocol != pyvban.const.VBANProtocols.VBAN_PROTOCOL_AUDIO: | ||
print(f"Received non audio packet {packet}") | ||
return | ||
if packet.header.stream_name != self._stream_name: | ||
print(f"Unexpected stream name \"{packet.header.stream_name}\" != \"{self._stream_name}\"") | ||
return | ||
if addr[0] != self._sender_ip: | ||
print(f"Unexpected sender \"{addr[0]}\" != \"{self._sender_ip}\"") | ||
return | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# import logging | ||
# import time | ||
|
||
# import pyvban | ||
|
||
# logging.basicConfig(level=logging.DEBUG) | ||
|
||
# pyvban.utils.device_list() | ||
|
||
# receiver = pyvban.utils.VBAN_Receiver( | ||
# sender_ip="127.0.0.1", | ||
# stream_name="Stream1", | ||
# port=6980, | ||
# device_index=11 | ||
# ) | ||
# receiver.run() | ||
|
||
# sender = pyvban.utils.VBAN_Sender( | ||
# receiver_ip="127.0.0.1", | ||
# receiver_port=6980, | ||
# stream_name="Stream1", | ||
# sample_rate=48000, | ||
# channels=2, | ||
# device_index=1 | ||
# ) | ||
# sender.run() | ||
|
||
# send_text = pyvban.utils.VBAN_SendText( | ||
# receiver_ip="127.0.0.1", | ||
# receiver_port=6980, | ||
# stream_name="Command1" | ||
# ) | ||
# state = False | ||
# while True: | ||
# state = not state | ||
# if state: | ||
# send_text.send("Strip[5].Mute = 0") | ||
# else: | ||
# send_text.send("Strip[5].Mute = 1") | ||
# time.sleep(1) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.