예제 #1
0
    def build(patch, locn=None, output="volcasamples.wav"):
        """
        Create a WAV file with patch data for a Volca device.

        :param [SyroData] patch: An array containing patch data.
        :param str locn: A path to a writeable directory.
        :param str output: The name of the output file.
        :return: A 2-tuple of (status, file path).
        :rtype: tuple

        """
        locn = locn or os.path.expanduser("~")
        fP = os.path.join(locn, output)
        handle = Handle()
        try:
            nFrames = SamplePacker.start(handle, patch, len(patch))
            rv = list(SamplePacker.get_samples(handle, nFrames))

            with wave.open(fP, "wb") as wav:
                wav.setparams(
                    wave._wave_params(nchannels=2,
                                      sampwidth=2,
                                      framerate=44100,
                                      nframes=nFrames,
                                      comptype="NONE",
                                      compname="not compressed"))
                for l, r in rv:
                    wav.writeframesraw(struct.pack("<hh", l, r))

        finally:
            return (SamplePacker.end(handle), fP)
예제 #2
0
파일: WavRead.py 프로젝트: NevynIt/SpecView
 def axes(self):
     params = self.params
     if params == None:
         params = wave._wave_params(1, 1, 1, 0, "NONE", "")
     self.time = linear_axis_info(params.nframes,
                                  step=1 / params.framerate,
                                  unit="s")
     self.channels = linear_axis_info(2)
     return (self.time, self.channels)
예제 #3
0
def writeAudio(audio, fileName):
    audioLength = len(audio)
    params = wave._wave_params(nchannels=1, sampwidth=1, framerate=11025/3, nframes=audioLength, comptype='NONE', compname='not compressed')
    audioFile = wave.open(fileName, 'wb')
    audioFile.setparams(params)
    # wavef.writeframes(audio)
    for value in audio:
        data = struct.pack('<B', value)
        audioFile.writeframesraw(data)
    audioFile.close()
    return 0
예제 #4
0
def writer(filename, nframes, dtype='int16', **params):
    """DEPRECATED"""
    with open(filename, mode='wb') as fp0:
        with wave.open(filename) as fp:
            params = dict(PARAMS, nframes=nframes, **params)
            max_size = 0x100000000 / params['nchannels'] / params['sampwidth']
            params['nframes'] = min(params['nframes'], int(max_size) - 1)
            wp = wave._wave_params(**params)
            fp.setparams(wp)
            shape = _shape(fp.getparams())
            offset = fp0.tell()

    return np.memmap(filename, dtype=dtype, offset=offset, shape=shape)
예제 #5
0
def decrypt_and_save(private_key, encrypted, filename):
    # decrypt
    decrypted = np.vectorize(private_key.decrypt)(encrypted)

    # save
    # create parameters
    params = wave._wave_params(nchannels=1,
                               sampwidth=2,
                               framerate=44100,
                               nframes=len(decrypted),
                               comptype='NONE',
                               compname='not compressed')
    # prepare data type
    dt = np.dtype('<i' +
                  str(params.sampwidth))  # '<': little endian, 'i': signed
    decrypted = decrypted.astype(np.int16, copy=False)
    # write
    f = wave.open(filename, mode='wb')
    f.setparams(params)
    f.writeframes(decrypted.tobytes())
    f.close()
예제 #6
0
import wave
import pyaudio
import pysoundio
import websockets
import asyncio
import logging
import queue

FORMAT = "%(levelname)s%(asctime)s -- \"%(message)s\""
logging.basicConfig(level=logging.INFO, format=FORMAT)

CHUNK = 1024
PATH = os.path.dirname(os.path.realpath(__file__))
FILE = PATH + "/transmission_file"
# Wav file params: channels, samplewidth, framerate, blocks, compression
WAV_PARAMS = wave._wave_params(1, 1, 8000, 0, 'NONE', 'not compressed')


class PyAudioStreamer:
    def __init__(self):
        self.CHUNK = CHUNK
        self.pyaudio_object = pyaudio.PyAudio()
        self.params = "1,2,44100"
        self.stream = self.pyaudio_object.open(
            channels=1,
            format=pyaudio.paInt16,
            rate=44100,
            input=True,
            frames_per_buffer=self.CHUNK,
        )
예제 #7
0
 def write(self, audio, fname):
     write_wave = wave.Wave_write(f"testGen/{fname}.wav")
     write_wave.setparams(wave._wave_params(1, 2, 22050, audio.shape[0], 'NONE', 'not compressed'))
     write_wave.writeframes(audio)
     write_wave.close()
 def test_get_parameters(self):
     ideal = wave._wave_params(nchannels=2, sampwidth=2, framerate=44100, nframes=44100 * 5, comptype='NONE',
                               compname='not compressed')
     self.assertEqual(ideal, self.wave.get_parameters())
예제 #9
0
import os
import asyncio
import logging
import time
import random as ra
import websockets
import wave

FORMAT = "%(levelname)s -- \"%(message)s\""
logging.basicConfig(level=logging.WARNING, format=FORMAT)

PATH = os.path.dirname(os.path.realpath(__file__))
FILE = PATH + "/THE_MAYOR_OF_WHOVILLE"
# Wav file params: channels, samplewidth, framerate, blocks, compression
MAYOR_PARAMS = wave._wave_params(1, 1, 8000, 128000, 'NONE', 'not compressed')


class Town:
    LISTENER_REQUEST = "I think you've assassinated the mayor! I demand to speak with them immedately!"
    MAYOR_REQUEST = "We need to speak to the Mayor!"
    MAYOR_KEEPALIVE = "We still have them, done worry!"
    MAYOR_RETURN = "The mayor has done us a great service!"
    TOWNSHIP_HANDSAKE = "I'm just a township"
    TRANSMISSION_COMPLETE = "The mayor is in town!"
    CONFIRMED = "Mayor will be right there!"
    DENIED = "Sorry, the mayor is indisposed at the moment"
    WAIT_RANGE = 10
    WAIT_MINIMUM = 5
    MAYOR_RETURN_CHANCE = 0.3
    CHUNK = 1024