Beispiel #1
0
    def play_looping(self, loop_start, loop_end, start_from=0):
        from mpg123 import ENC_FLOAT_32, Out123

        out = Out123()

        out.start(self.rate, self.channels, ENC_FLOAT_32)

        playback_frames = librosa.util.frame(self.playback_audio.flatten(order="F"), frame_length=2048, hop_length=512)
        loop_start = loop_start * self.channels
        loop_end = loop_end * self.channels
        start_from = start_from * self.channels

        i = start_from
        idx_end = playback_frames.shape[-1]
        loop_count = 0
        try:
            while True:
                out.play(playback_frames[..., i])
                i += 1
                if i >= loop_end or i >= idx_end:
                    i = loop_start
                    loop_count += 1
                    print("Currently on loop #{}".format(loop_count), end="\r")

        except KeyboardInterrupt:
            print("\rPlayer will not loop. Ctrl+C again to stop playback.")
            try:
                for i in range(i, idx_end):
                    out.play(playback_frames[..., i])
            except KeyboardInterrupt:
                print()
Beispiel #2
0
def guide(ment):

    global start_check
    start_check = False
    mp3 = Mpg123(ment)
    out = Out123()

    for frame in mp3.iter_frames(out.start):
        out.play(frame)
Beispiel #3
0
def playMP3(filename):
    try:
        from mpg123 import Mpg123, Out123
        mp3 = Mpg123(filename)
        out = Out123()
        for frame in mp3.iter_frames(out.start):
            out.play(frame)
    except ValueError:
        print(ValueError)
Beispiel #4
0
 def play_looping(self, start_offset, loop_offset):
     out = Out123()
     out.start(self.rate, self.channels, self.encoding)
     i = 0
     try:
         while True:
             out.play(self.frames[i])
             i += 1
             if i == loop_offset:
                 i = start_offset
     except KeyboardInterrupt:
         print()  # so that the program ends on a newline
Beispiel #5
0
 def play(self, start, end, loop=False):
     out = Out123()
     out.start(self.rate, self.channels, self.encoding)
     i = 0
     try:
         while loop:
             out.play(self.frames[i])
             i += 1
             if i == end:
                 i = start
     except KeyboardInterrupt:
         print() # so that the program ends on a newline
Beispiel #6
0
def playMusic(audiocard, filename):
    if checkAppStopAction():
        return
    try:
        '''
        if audiocard is None or audiocard=='':
            os.system('mpg321 "'+filename+'"') 
        else:
            os.system('mpg321 -o alsa -a '+audiocard +' "'+filename+'"') 
        '''

        mp3 = Mpg123(filename)
        out = Out123()
        for frame in mp3.iter_frames(out.start):
            out.play(frame)

        #os.system('mpg123 '+filename+'')
    except Exception as err:
        logger.error("音乐播放出现错误" + filename + ",%s", err)
Beispiel #7
0
def audio_describe(codes):
    text = ''
    for code, count in codes.items():
        if code == 'thumbs_up':
            text += f'{count} users are presenting thumbs-up, '
        elif code == 'smiling':
            text += f'{count} users are smiling, '

    if text == '':
        return

    with io.BytesIO() as f:
        gTTS(text=text, lang='en', slow=False).write_to_fp(f)
        f.seek(0)
        mp3 = Mpg123()
        mp3.feed(f.read())
        out = Out123()
        for frame in mp3.iter_frames(out.start):
            out.play(frame)
Beispiel #8
0
from mpg123 import Mpg123, Out123
import asyncio
import aiohttp

mp3 = Mpg123()

out = Out123()


async def radio_streaming(mp3, out):
    async with aiohttp.ClientSession() as session:
        async with session.get(
                'http://stream.radiometal.com:8010') as response:
            while True:
                chunk = await response.content.read(4096)
                if not chunk:
                    break
                mp3.feed(chunk)
                for frame in mp3.iter_frames(out.start):
                    out.play(frame)


loop = asyncio.get_event_loop()
loop.run_until_complete(radio_streaming(mp3, out))
Beispiel #9
0
def timetalk():
    hour = datetime.now().strftime("%-I")
    mp3 = Mpg123("resourses/" + hour + ".mp3")
    out = Out123()
    for frame in mp3.iter_frames(out.start):
        out.play(frame)
from mpg123 import Mpg123, Out123

### Configs ###
COIN_SOUND = 'coin'
BRICK_SOUND = 'brick'
COIN_SOUND_PATH = 'resources/mp3/coin.mp3'
BRICK_SOUND_PATH = 'resources/mp3/brick.mp3'

coin_sound = Mpg123(COIN_SOUND_PATH)
brick_sound = Mpg123(BRICK_SOUND_PATH)
sound_interface = Out123()


def play_sound(sound_type):
    ## Choice to use mpg123 os library, or pip library
    # e.g. `os.system('mpg123 -q resources/mp3/coin.mp3 &')`
    if sound_type == COIN_SOUND:
        sound = coin_sound
    elif sound_type == BRICK_SOUND:
        sound = brick_sound

        for frame in sound.iter_frames(sound_interface.start):
            sound_interface.play(frame)
Beispiel #11
0
def main():
    mp3 = Mpg123("tm.mp3")
    out = Out123()
    for frame in mp3.iter_frames(out.start):
        out.play(frame)
Beispiel #12
0
 def setup_mp3(self):
     self.mp3 = Mpg123(self.loc)
     self.mpgout = Out123()
     self.frames = self.mp3.iter_frames(self.mpgout.start)