-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from arushsharma24/main
Linux : Virtual device creation and routing microphone audio via a python script
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 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,3 +1,5 @@ | ||
#Temporary work files | ||
linux/initial | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
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,9 @@ | ||
### Step 1: | ||
Run the script with the command: | ||
`$ python3 dynopii.py` | ||
|
||
### Step 2: (only for first time use) | ||
In the "Playback" tab of the pavucontrol window that opens, and make sure that the playback device for the running "ALSA plug-in[aplay]: ALSA Playback _on_" is 'dynopii'. | ||
|
||
# | ||
To close this, stop the script using `Ctrl-C` and it will also delete the virtual device module and stop the playback. |
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,49 @@ | ||
import subprocess | ||
import audioop | ||
|
||
try: | ||
|
||
print('#' * 80) | ||
print('Initiating dynopii virtual audio cable ... ') | ||
loadcmd = ['pacmd', 'load-module', 'module-null-sink', 'sink_name=dynopii_sink', 'sink_properties=device.description=dynopii'] | ||
subprocess.Popen(loadcmd) | ||
subprocess.Popen('pavucontrol') | ||
|
||
cmd0 = ['arecord', '-f', 'cd', '-'] | ||
p0 = subprocess.Popen(cmd0, stdout=subprocess.PIPE) | ||
|
||
''' | ||
This stdout of p0 is basically the data we get from arecord, and the data that we can manipulate on the fly and then | ||
feed to the stdin of the next process p1. | ||
If you will work on this, you'll have to replace the stdin=p0.stdout of the following process p1 with your manipulated data. | ||
''' | ||
|
||
cmd1 = ['aplay', '-f', 'cd', '-'] | ||
p1 = subprocess.Popen(cmd1, stdin=p0.stdout) | ||
print('') | ||
print('To quit this program and close your virtual device, press Ctrl-C') | ||
print('') | ||
print('#' * 80) | ||
input() | ||
|
||
except EOFError: | ||
print('EOF Error') | ||
|
||
except KeyboardInterrupt: | ||
print() | ||
print('Closing the virtual audio cable ....') | ||
print('Unloading null-sinks ...') | ||
print('Stopping playback ...') | ||
|
||
uncmd0 = ['pactl', 'list', 'short', 'modules'] | ||
uncmd1 = ['grep', 'sink_name=dynopii'] | ||
uncmd2 = [ 'cut', '-f1' ] | ||
uncmd3 = [ 'xargs', '-L1', 'pactl', 'unload-module' ] | ||
|
||
unp0 = subprocess.Popen(uncmd0, stdout=subprocess.PIPE) | ||
unp1 = subprocess.Popen(uncmd1, stdin=unp0.stdout, stdout=subprocess.PIPE) | ||
unp2 = subprocess.Popen(uncmd2, stdin=unp1.stdout, stdout=subprocess.PIPE) | ||
unp3 = subprocess.Popen(uncmd3, stdin=unp2.stdout) | ||
|
||
killcmd = ['pkill', 'arecord'] #kill arecord (hence killing ALSA playback since aplay simultaneously stops receiving input via the pipe) | ||
closefin = subprocess.Popen(killcmd) |