示例#1
0
def _main():
    """
    For testing.
    """
    import os
    import math
    import stdio
    import instream

    _createTextAudioFile()

    stdio.writeln('Creating and playing in small chunks...')
    sps = _SAMPLES_PER_SECOND
    inStream = instream.InStream('looney.txt')
    while not inStream.isEmpty():
        pitch = inStream.readInt()
        duration = inStream.readFloat()
        hz = 440 * math.pow(2, pitch / 12.0)
        N = int(sps * duration)
        notes = []
        for i in range(N+1):
            notes.append(math.sin(2*math.pi * i * hz / sps))
        playSamples(notes)
    wait()

    stdio.writeln('Creating and playing in one large chunk...')
    sps = _SAMPLES_PER_SECOND
    notes = []
    inStream = instream.InStream('looney.txt')
    while not inStream.isEmpty():
        pitch = inStream.readInt()
        duration = inStream.readFloat()
        hz = 440 * math.pow(2, pitch / 12.0)
        N = int(sps * duration)
        for i in range(N+1):
            notes.append(math.sin(2*math.pi * i * hz / sps))
    playSamples(notes)
    wait()

    stdio.writeln('Saving...')
    save('looney', notes)

    stdio.writeln('Reading...')
    notes = read('looney')

    stdio.writeln('Playing an array...')
    playSamples(notes)
    wait()

    stdio.writeln('Playing a file...')
    playFile('looney')
    wait()

    os.remove('looney.wav')
    os.remove('looney.txt')
示例#2
0
def _main():
    """
    For testing.
    """
    import math
    import instream

    _create_text_audio_file()

    stdio.writeln('Creating and playing in small chunks...')
    sps = _SAMPLES_PER_SECOND
    _instream = instream.InStream('looney.txt')
    while not _instream.is_empty():
        pitch = _instream.read_int
        duration = _instream.read_float()
        hz = 440 * math.pow(2, pitch / 12.0)
        n = int(sps * duration)
        notes = []
        for i in range(n + 1):
            notes.append(math.sin(2 * math.pi * i * hz / sps))
        play_samples(notes)
    wait()

    stdio.writeln('Creating and playing in one large chunk...')
    sps = _SAMPLES_PER_SECOND
    notes = []
    _instream = instream.InStream('looney.txt')
    while not _instream.is_empty():
        pitch = _instream.read_int
        duration = _instream.read_float()
        hz = 440 * math.pow(2, pitch / 12.0)
        n = int(sps * duration)
        for i in range(n + 1):
            notes.append(math.sin(2 * math.pi * i * hz / sps))
    play_samples(notes)
    wait()

    stdio.writeln('Saving...')
    save('looney', notes)

    stdio.writeln('Reading...')
    notes = read('looney')

    stdio.writeln('Playing an array...')
    play_samples(notes)
    wait()

    stdio.writeln('Playing a file...')
    play_file('looney')
    wait()

    os.remove('looney.wav')
    os.remove('looney.txt')
示例#3
0
def main():
    """
    For testing.
    """
    import math
    import stdio
    import instream

    stdio.writeln('Playing')
    playFile('woman.wav')

    stdio.writeln('Reading')
    samples = read('woman.wav')
    stdio.writeln('Playing')
    playArray(samples)

    stdio.writeln('Creating and playing in small chunks')
    sps = _SAMPLES_PER_SECOND
    inStream = instream.InStream('elise.txt')
    while not inStream.isEmpty():
        pitch = inStream.readInt()
        duration = inStream.readFloat()
        hz = 440 * math.pow(2, pitch / 12.0)
        N = int(sps * duration)
        notes = []
        for i in range(N+1):
            notes.append(math.sin(2*math.pi * i * hz / sps))
        playArray(notes)
    wait()

    stdio.writeln('Creating and playing in one large chunk')
    sps = _SAMPLES_PER_SECOND
    notes = []
    inStream = instream.InStream('looney.txt')
    while not inStream.isEmpty():
        pitch = inStream.readInt()
        duration = inStream.readFloat()
        hz = 440 * math.pow(2, pitch / 12.0)
        N = int(sps * duration)
        for i in range(N+1):
            notes.append(math.sin(2*math.pi * i * hz / sps))
    playArray(notes)
    wait()

    stdio.writeln('Saving')
    save('zzz.wav', notes)
    stdio.writeln('Reading')
    notes = read('zzz.wav')
    stdio.writeln('Playing')
    playArray(notes)
    wait()
def main():
    inStream = instream.InStream(sys.argv[1])
    a = inStream.readAllStrings()

    while not stdio.isEmpty():
        key = stdio.readString()
        if search(key, a) < 0:
            stdio.writeln(key)