예제 #1
0
    group_start = time.time();
    packet_start = group_start;

    while (True):
        for i in range(packet_count):
            try:
                sock.send(next(packet_data))
                packet_start += packet_period
                packet_sleep = packet_start - time.time()
                if packet_sleep > 0:
                    time.sleep(packet_sleep)
            except Exception as e:
                sys.stderr.write('E')
                print(e)
                time.sleep(1)

        group_stop = time.time()
        sample_count = packet_count * packet_samples
        sample_time = group_stop - group_start
        group_start = group_stop
        sys.stderr.write('{0} Hz\n'.format(int(sample_count / sample_time)))


if __name__ == '__main__':
    if len(sys.argv) != 4:
        sys.stderr.write('Usage: {0} <spark ip> <spark port> <audio file>\n')
    else:
        data = convert_buffer(read_sound(sys.argv[3]))
        stream_buffer(sys.argv[1], int(sys.argv[2]), data)
예제 #2
0
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import numpy
import pysoundfile
import sys


from make_sample import convert_buffer, read_sound


def write_bin(path, data):
    fp = open(path, 'wb')

    # Write bytes MSB first
    data = data.astype(numpy.dtype('>u2'))

    for i in range(0, data.size, 1024):
        fp.write(data[i:i + 1024].tostring())

    fp.close()


if __name__ == '__main__':
    if len(sys.argv) != 3:
        print('Usage: {0} audio_sample.ogg audio_sample.bin')
    else:
        sound = read_sound(sys.argv[1])
        data = convert_buffer(sound)
        write_bin(sys.argv[2], data)