How to use the amodem.audio.Interface function in amodem

To help you get started, we’ve selected a few amodem examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github romanz / amodem / tests / test_audio.py View on Github external
def test():
    length = 1024
    data = b'\x12\x34' * length
    with mock.patch('ctypes.CDLL') as cdll:
        lib = mock.Mock()
        lib.Pa_GetErrorText = lambda code: b'Error' if code else b'Success'
        lib.Pa_GetDefaultOutputDevice.return_value = 1
        lib.Pa_GetDefaultInputDevice.return_value = 2
        lib.Pa_OpenStream.return_value = 0
        cdll.return_value = lib
        interface = audio.Interface(config=config.fastest(), debug=True)
        assert interface.load(name='portaudio') is interface
        with interface:
            s = interface.player()
            assert s.params.device == 1
            s.stream = 1  # simulate non-zero output stream handle
            s.write(data=data)
            s.close()

        with interface:
            s = interface.recorder()
            assert s.params.device == 2
            s.stream = 2  # simulate non-zero input stream handle
            s.read(len(data))
            s.close()

        with pytest.raises(Exception):
github AXErunners / electrum-axe / electrum_axe / plugins / audio_modem / qt.py View on Github external
def _audio_interface(self):
        interface = amodem.audio.Interface(config=self.modem_config)
        return interface.load(self.library_name)
github romanz / amodem / scripts / record.py View on Github external
def run(args):
    config = Configuration()
    with open(args.filename, 'wb') as dst:
        interface = audio.Interface(config=config)
        with interface.load(args.audio_library):
            src = interface.recorder()
            size = int(config.sample_size * config.Fs)  # one second of audio
            while True:
                dst.write(src.read(size))
github romanz / amodem / amodem / __main__.py View on Github external
args.pylab = None
    if getattr(args, 'plot', False):
        import pylab  # pylint: disable=import-error
        args.pylab = pylab

    if args.audio_library == 'ALSA':
        from . import alsa
        interface = alsa.Interface(config)
    elif args.audio_library == '-':
        interface = _Dummy()  # manually disable PortAudio
    elif args.command == 'send' and args.output is not None:
        interface = _Dummy()  # redirected output
    elif args.command == 'recv' and args.input is not None:
        interface = _Dummy()  # redirected input
    else:
        interface = audio.Interface(config)
        interface.load(args.audio_library)

    with interface:
        args.src = args.input_type(args.input)
        args.dst = args.output_type(args.output)
        try:
            if args.calibrate is False:
                args.main(config=config, args=args)
            else:
                args.calib(config=config, args=args)
        finally:
            args.src.close()
            args.dst.close()
            log.debug('Finished I/O')
github etotheipi / BitcoinArmory / samplemodules / AudioTransferPlugin.py View on Github external
from qtdefines import QRichLabel, makeHorizFrame, GETFONT, relaxedSizeNChar, \
   makeVertFrame, NETWORKMODE
from PyQt4 import QtGui

import StringIO
import logging
import zlib

from amodem import recv, send, audio, async
from amodem import main as mainAudio
from amodem.config import bitrates


BITRATE = 48
CONFIG = bitrates.get(int(BITRATE))
AUDIO_INTERFACE = audio.Interface(config=CONFIG)
AUDIO_LIBRARY = "libportaudio.so"
level, fmt = ('DEBUG', '%(asctime)s %(levelname)-10s '
              '%(message)-100s '
              '%(filename)s:%(lineno)d')
logging.basicConfig(level=level, format=fmt)


class PluginObject(object):

   tabName = 'Audio Transfer'
   maxVersion = '0.93.99'
   
   #############################################################################
   def __init__(self, main):
      self.main = main
      mode = self.main.netMode
github qtumproject / qtum-electrum / qtum_electrum / plugins / audio_modem / qt.py View on Github external
def _audio_interface(self):
        interface = amodem.audio.Interface(config=self.modem_config)
        return interface.load(self.library_name)
github spesmilo / electrum / electrum / plugins / audio_modem / qt.py View on Github external
def _audio_interface(self):
        interface = amodem.audio.Interface(config=self.modem_config)
        return interface.load(self.library_name)