Beispiel #1
0
def key_poller():

    shutdown = False

    key_map = {}
    for c in range(97, 123):
        key_map[chr(c)] = False

    rate = rospy.Rate(10)

    w = sf.RenderWindow(sf.VideoMode(640, 480), "tele-op",
                        sf.Style.TITLEBAR | sf.Style.RESIZE)
    while not rospy.is_shutdown() and not shutdown:
        for event in w.events:
            # Handle shutdown
            if type(event) is sf.KeyEvent and event.code is sf.Keyboard.ESCAPE:
                w.close()
                shutdown = True

            if type(event
                    ) is sf.KeyEvent and 0 <= event.code and event.code < 26:
                key = chr(event.code + 97)
                if (event.pressed):
                    key_map[key] = True

                if (event.released):
                    key_map[key] = False

        publish_cmd_vel(key_map)
        sf.sleep(sf.seconds(0.05))
Beispiel #2
0
def main():
    # check that the device can capture audio
    if not sf.SoundRecorder.is_available():
        print("Sorry, audio capture is not supported by your system")
        return

    # choose the sample rate
    sample_rate = int(
        input(
            "Please choose the sample rate for sound capture (44100 is CD quality): "
        ))

    # wait for user input...
    input("Press enter to start recording audio")

    # here we'll use an integrated custom recorder, which saves the captured data into a sf.SoundBuffer
    recorder = sf.SoundBufferRecorder()

    # audio capture is done in a separate thread, so we can block the main thread while it is capturing
    recorder.start(sample_rate)
    input("Recording... press enter to stop")
    recorder.stop()

    # get the buffer containing the captured data
    buffer = recorder.buffer

    # display captured sound informations
    print("Sound information:")
    print("{0} seconds".format(buffer.duration))
    print("{0} samples / seconds".format(buffer.sample_rate))
    print("{0} channels".format(buffer.channel_count))

    # choose what to do with the recorded sound data
    choice = input(
        "What do you want to do with captured sound (p = play, s = save) ? ")

    if choice == 's':
        # choose the filename
        filename = input("Choose the file to create: ")

        # save the buffer
        buffer.to_file(filename)
    else:
        # create a sound instance and play it
        sound = sf.Sound(buffer)
        sound.play()

        # wait until finished
        while sound.status == sf.Sound.PLAYING:
            # leave some CPU time for other threads
            sf.sleep(sf.milliseconds(100))

    # finished !
    print("Done !")

    # wait until the user presses 'enter' key
    input("Press enter to exit...")
Beispiel #3
0
def main():
    # check that the device can capture audio
    if not sf.SoundRecorder.is_available():
        print("Sorry, audio capture is not supported by your system")
        return

    # choose the sample rate
    sample_rate = int(input("Please choose the sample rate for sound capture (44100 is CD quality): "))

    # wait for user input...
    input("Press enter to start recording audio")

    # here we'll use an integrated custom recorder, which saves the captured data into a sf.SoundBuffer
    recorder = sf.SoundBufferRecorder()

    # audio capture is done in a separate thread, so we can block the main thread while it is capturing
    recorder.start(sample_rate)
    input("Recording... press enter to stop")
    recorder.stop()

    # get the buffer containing the captured data
    buffer = recorder.buffer

    # display captured sound informations
    print("Sound information:")
    print("{0} seconds".format(buffer.duration))
    print("{0} samples / seconds".format(buffer.sample_rate))
    print("{0} channels".format(buffer.channel_count))

    # choose what to do with the recorded sound data
    choice = input("What do you want to do with captured sound (p = play, s = save) ? ")

    if choice == 's':
        # choose the filename
        filename = input("Choose the file to create: ")

        # save the buffer
        buffer.to_file(filename);
    else:
        # create a sound instance and play it
        sound = sf.Sound(buffer)
        sound.play();

        # wait until finished
        while sound.status == sf.Sound.PLAYING:
            # leave some CPU time for other threads
            sf.sleep(sf.milliseconds(100))

    # finished !
    print("Done !")

    # wait until the user presses 'enter' key
    input("Press enter to exit...")
Beispiel #4
0
def play_music():
    # load an ogg music file
    music = sf.Music.from_file("data/orchestral.ogg")

    # display music informations
    print("orchestral.ogg:")
    print("{0} seconds".format(music.duration))
    print("{0} samples / sec".format(music.sample_rate))
    print("{0} channels".format(music.channel_count))

    # play it
    music.play()

    # loop while the music is playing
    while music.status == sf.Music.PLAYING:
        # leave some CPU time for other processes
        sf.sleep(sf.milliseconds(100))
Beispiel #5
0
def play_music():
    # load an ogg music file
    music = sf.Music.from_file("data/orchestral.ogg")

    # display music informations
    print("orchestral.ogg:")
    print("{0} seconds".format(music.duration))
    print("{0} samples / sec".format(music.sample_rate))
    print("{0} channels".format(music.channel_count))

    # play it
    music.play();

    # loop while the music is playing
    while music.status == sf.Music.PLAYING:
        # leave some CPU time for other processes
        sf.sleep(sf.milliseconds(100))
Beispiel #6
0
def play_sound():
    # load a sound buffer from a wav file
    buffer = sf.SoundBuffer.from_file("data/canary.wav")

    # display sound informations
    print("canary.wav:")
    print("{0} seconds".format(buffer.duration))
    print("{0} samples / sec".format(buffer.sample_rate))
    print("{0} channels".format(buffer.channel_count))

    # create a sound instance and play it
    sound = sf.Sound(buffer)
    sound.play()

    # loop while the sound is playing
    while sound.status == sf.Sound.PLAYING:
        # leave some CPU time for other processes
        sf.sleep(sf.milliseconds(100))
Beispiel #7
0
 def soundMaker(self, tinfo=""):
     """
     Create the background music.
     """
     uargv = ""
     if (self.debug1):
         print("\n\tThe thread", tinfo, "is starting.")
     uargv = tinfo.upper()
     buffer = sf.SoundBuffer.from_file(self.soundFile)
     if (not buffer):
         print("\n\tUnable to load the sound", self.soundFile, ".")
     sound = sf.Sound(buffer)
     sound.loop = True
     while (True):
         sound.play()
         sf.sleep(sf.seconds(300))
     if (self.debug1):
         print("\n\tThe thread", uargv, "is terminated.")
Beispiel #8
0
def play_sound():
    # load a sound buffer from a wav file
    buffer = sf.SoundBuffer.from_file("data/canary.wav")

    # display sound informations
    print("canary.wav:")
    print("{0} seconds".format(buffer.duration))
    print("{0} samples / sec".format(buffer.sample_rate))
    print("{0} channels".format(buffer.channel_count))

    # create a sound instance and play it
    sound = sf.Sound(buffer)
    sound.play();

    # loop while the sound is playing
    while sound.status == sf.Sound.PLAYING:
        # leave some CPU time for other processes
        sf.sleep(sf.milliseconds(100))
Beispiel #9
0
def do_server(port):
    # build an audio stream to play sound data as it is received through the network
    audio_stream = NetworkAudioStream()
    audio_stream.start(port)

    # loop until the sound playback is finished
    while audio_stream.status != sf.SoundStream.STOPPED:
        # leave some CPU time for other threads
        sf.sleep(sf.milliseconds(100))


    # wait until the user presses 'enter' key
    input("Press enter to replay the sound...")

    # replay the sound (just to make sure replaying the received data is OK)
    audio_stream.play();

    # loop until the sound playback is finished
    while audio_stream.status != sf.SoundStream.STOPPED:
        sf.sleep(sf.milliseconds(100))
Beispiel #10
0
    def on_get_data(self, chunk):
        # we have reached the end of the buffer and all audio data have been played : we can stop playback
        if self.offset >= len(self.samples) and self.has_finished:
            return False

        # no new data has arrived since last update : wait until we get some
        while self.offset >= len(self.samples) and not self.has_finished:
            sf.sleep(sf.milliseconds(10))

        # don't forget to lock as we run in two separate threads
        lock = threading.Lock()
        lock.acquire()

        # fill audio data to pass to the stream
        chunk.data = self.samples.data[self.offset*2:]

        # update the playing offset
        self.offset += len(chunk)

        lock.release()

        return True
Beispiel #11
0
def test_timer(timer):
    timer.restart(sf.seconds(1))
    timer.start()
    sf.sleep(sf.seconds(0.2))
    print(timer.remaining_time)
    print(timer.is_running())
    print(timer.is_expired())
    sf.sleep(sf.seconds(0.5))

    timer.reset(sf.seconds(0.2))
    print(timer.is_running())
    timer.start()

    while timer.is_running():
        sf.sleep(sf.seconds(0.025))
        print(timer.remaining_time)

    print(timer.is_expired())
Beispiel #12
0
from sfml import sf
from thor import th

# TEST #001 th.StopWatch
stopwatch = th.StopWatch()
stopwatch.start()
sf.sleep(sf.seconds(1))
print(stopwatch.elapsed_time)

print(stopwatch.is_running())
stopwatch.stop()
print(stopwatch.is_running())
stopwatch.reset()
stopwatch.restart()

def test_timer(timer):
    timer.restart(sf.seconds(1))
    timer.start()
    sf.sleep(sf.seconds(0.2))
    print(timer.remaining_time)
    print(timer.is_running())
    print(timer.is_expired())
    sf.sleep(sf.seconds(0.5))

    timer.reset(sf.seconds(0.2))
    print(timer.is_running())
    timer.start()

    while timer.is_running():
        sf.sleep(sf.seconds(0.025))
        print(timer.remaining_time)
Beispiel #13
0
from sfml import sf

import pyximport; pyximport.install()
import extension

window = sf.RenderWindow(sf.VideoMode(640, 480), "sfml")

image = sf.Image.from_file("image.jpg")
extension.flip_image(image)

texture = sf.Texture.from_image(image)

window.clear()
window.draw(sf.Sprite(texture))
window.display()

sf.sleep(sf.seconds(5))