Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up audinterface.Segment #106

Closed
hagenw opened this issue Mar 13, 2023 · 0 comments · Fixed by #107
Closed

Speed up audinterface.Segment #106

hagenw opened this issue Mar 13, 2023 · 0 comments · Fixed by #107
Labels
enhancement New feature or request

Comments

@hagenw
Copy link
Member

hagenw commented Mar 13, 2023

Similar to #100 we want to speed up audinterface.Segment when processing several files.

At the moment we get:

import pandas as pd

import audb
import audinterface
import audiofile


db = audb.load(
    'emodb',
    version='1.3.0',
    format='wav',
    sampling_rate=16000,
    mixdown=True,
)
files = db.files

def process_func(x, sr):
    return pd.MultiIndex.from_tuples(
        [(pd.to_timedelta(0), pd.to_timedelta(1))],
        names=['start', 'end'],
    )

# slow

segment = audinterface.Segment(
    process_func=process_func,
)

t = time.time()
index_slow = segment.process_files(files)
print(time.time() - t)

# fast

t = time.time()
starts = []
ends = []
for idx, file in enumerate(files):
    signal, sampling_rate = audiofile.read(file)
    index = process_func(
        signal,
        sampling_rate,
    )
    starts += list(index.get_level_values('start'))
    ends += list(index.get_level_values('end'))

index_fast = pd.MultiIndex.from_arrays(
    [files, starts, ends],
    names=['file', 'start', 'end'],
)
print(time.time() - t)

pd.testing.assert_index_equal(index_slow, index_fast)
4.128075122833252                                                                                   
1.7938168048858643
@hagenw hagenw changed the title Speed up Segment Speed up audinterface.Segment Mar 13, 2023
@hagenw hagenw added the enhancement New feature or request label Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant