Browse Source

Update for amodem v1.5

- amodem does not depend on pyaudio (only on numpy)
- use ctypes to access PortAudio API
283
Roman Zeyde 10 years ago
parent
commit
7833055308
  1. 23
      plugins/audio_modem.py

23
plugins/audio_modem.py

@ -11,9 +11,13 @@ import zlib
import json import json
from io import BytesIO from io import BytesIO
import sys import sys
import platform
try: try:
import amodem import amodem.audio
import amodem.recv
import amodem.send
import amodem.config
print_msg('Audio MODEM is enabled.') print_msg('Audio MODEM is enabled.')
amodem.log.addHandler(amodem.logging.StreamHandler(sys.stderr)) amodem.log.addHandler(amodem.logging.StreamHandler(sys.stderr))
amodem.log.setLevel(amodem.logging.INFO) amodem.log.setLevel(amodem.logging.INFO)
@ -28,6 +32,9 @@ class Plugin(BasePlugin):
BasePlugin.__init__(self, config, name) BasePlugin.__init__(self, config, name)
if self.is_available(): if self.is_available():
self.modem_config = amodem.config.slowest() self.modem_config = amodem.config.slowest()
self.library_name = {
'Linux': 'libportaudio.so'
}[platform.system()]
def fullname(self): def fullname(self):
return 'Audio MODEM' return 'Audio MODEM'
@ -100,12 +107,18 @@ class Plugin(BasePlugin):
button = add_button(parent=parent, icon_name=':icons/speaker.png') button = add_button(parent=parent, icon_name=':icons/speaker.png')
button.clicked.connect(handler) button.clicked.connect(handler)
def _audio_interface(self):
return amodem.audio.Interface(
config=self.modem_config,
name=self.library_name
)
def _send(self, parent, blob): def _send(self, parent, blob):
def sender_thread(): def sender_thread():
try: try:
audio_interface = amodem.audio.Interface(self.modem_config) with self._audio_interface() as interface:
src = BytesIO(blob) src = BytesIO(blob)
dst = audio_interface.player() dst = interface.player()
amodem.send.main(config=self.modem_config, src=src, dst=dst) amodem.send.main(config=self.modem_config, src=src, dst=dst)
except Exception: except Exception:
traceback.print_exc() traceback.print_exc()
@ -120,8 +133,8 @@ class Plugin(BasePlugin):
def _recv(self, parent): def _recv(self, parent):
def receiver_thread(): def receiver_thread():
try: try:
audio_interface = amodem.audio.Interface(self.modem_config) with self._audio_interface() as interface:
src = audio_interface.recorder() src = interface.recorder()
dst = BytesIO() dst = BytesIO()
amodem.recv.main(config=self.modem_config, src=src, dst=dst) amodem.recv.main(config=self.modem_config, src=src, dst=dst)
return dst.getvalue() return dst.getvalue()

Loading…
Cancel
Save