System for concatenating sounds

This is the place for queries that don't fit in any of the other categories.

System for concatenating sounds

Postby savagecreature » Sat Jul 27, 2013 4:25 pm

I'm looking for general advice moving to the more specific.
Though I'm not new to Python, I've never done sound in python before, so please bear with me.

I've got sound files of phonemes, individual linguistic sounds, that I want to be able to concatenate into 'words' and then play them back. I've got sounds playing in PyGame, but they all play at the same time. I've seen code that forces the system to wait until playback is complete, but all the examples fully occupy the processing cycles until the sound is done. I'm trying to find a method that will play "snd_file_01" and then "snd_file_02" in succession (instead of simultaneously) the most efficient way I can.

I've had a look at snack, but haven't been able to successfully install it on my Debian system.

Any awesome suggestions?

thanks
savagecreature
 
Posts: 1
Joined: Sat Jul 27, 2013 4:16 pm

Re: System for concatenating sounds

Postby Yoriz » Sat Jul 27, 2013 6:10 pm

You could give this module a try, i have not used it so i can't vouch for it.
pyDub
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Yoriz
 
Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: System for concatenating sounds

Postby dstahlberg » Thu Dec 25, 2014 4:08 pm

Hello savagecreature,

Any luck in finding some software for concatenating sounds? I have a similar need, but can't really find a good module either. Snack seems a bit old at first glance ... (2004 according to KTH site).
Last edited by micseydel on Thu Dec 25, 2014 5:55 pm, edited 1 time in total.
Reason: First post lock.
dstahlberg
 
Posts: 1
Joined: Thu Dec 25, 2014 3:49 pm
Location: Stockholm, Sweden

Re: System for concatenating sounds

Postby metulburr » Thu Dec 25, 2014 9:41 pm

I've got sounds playing in PyGame, but they all play at the same time.

If your are already using pygame, why not just use pygame?

I'm trying to find a method that will play "snd_file_01" and then "snd_file_02" in succession (instead of simultaneously) the most efficient way I can.

You can use mixer.music from pygame. There is no need to use other modules. This plays all wavs in current directory one after the other endlessly.
Code: Select all
import pygame as pg
import os

class Sound:
    def __init__(self, volume):
        self.path = '.'
        self.allowed_exts = ['.wav']
        self.setup(volume)
       
    def setup(self, volume):
        self.track_end = pg.USEREVENT+1
        self.tracks = []
        self.track = 0
        for track in os.listdir(self.path):
            for ext in self.allowed_exts:
                if track.endswith(ext):
                    self.tracks.append(os.path.join(self.path, track))
        #random.shuffle(self.tracks)
        pg.mixer.music.set_volume(volume)
        pg.mixer.music.set_endevent(self.track_end)
        pg.mixer.music.load(self.tracks[0])

pg.init()
screen = pg.display.set_mode((600,400))
done = False
sound = Sound(.5)
pg.mixer.music.play()
while not done:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            done = True
        elif event.type == sound.track_end:
            sound.track = (sound.track+1) % len(sound.tracks)
            pg.mixer.music.load(sound.tracks[sound.track])
            pg.display.set_caption(sound.tracks[sound.track])
            pg.mixer.music.play()
    pg.display.update()
pg.quit()
we will be moving to python-forum.io on October 1 2016
more details here
User avatar
metulburr
 
Posts: 2243
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot] and 6 guests