Ejemplo n.º 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)
Ejemplo n.º 2
0
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import numpy
import sys

from make_sample import AUDIO_FREQUENCY, convert_buffer, write_samples


def make_sine(frequency):
    period_samples = int(AUDIO_FREQUENCY / frequency)
    x = numpy.linspace(-numpy.pi, numpy.pi, period_samples)
    return numpy.sin(x[:-1])


if __name__ == '__main__':
    if len(sys.argv) != 2:
        print('Usage: {0} frequency')
    else:
        data = make_sine(int(sys.argv[1]))
        data = convert_buffer(data)
        write_samples(data)
Ejemplo n.º 3
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)