steelegbr / wave-chunk-parser

Parses wave file chunks.
Apache License 2.0
9 stars 4 forks source link

`waveparser.py`: How can we add a `CueChunk` with an `LabeledTextChunk` to set the cue marker length? #173

Closed schittli closed 1 year ago

schittli commented 1 year ago

Good evening,

Important Note: I am pretty sure that this issue is related to this one: https://github.com/steelegbr/wave-chunk-parser/issues/174

thank you very much for sharing your great an very useful work! I guess you wrote that "writing this code was not rocket science" but if one has no idea about riff & co it is very confusing and feels like quantum physics 😃

I have a question to the CuePoint:

In the example code of waveparser.py, in the function test_set_cue_points(fname_in, fname_out): you create the CuePoint like this:

def test_set_cue_points(fname_in, fname_out):
    """
    Test : add cue points and modify infos
    """
    … 
    pos = int(1.0 * rate)
    chunk_cue.cue_points.append(CuePoint(id_cue, pos, b"data", 0, 0, pos))
    assocs.append(LabelChunk(id_cue, "First added"))

Now, finally the question: how can we add a LabeledTextChunk object, to a CueChunk?

I have tried different solutions, but all of them raise an exception as soon as I call riff_chunk.to_bytes() 😢. Here, I display my Trials #1 and #2:

def test_set_cue_points(fname_in, fname_out):
    """
    Test : add cue points and modify infos
    """
    … 
    pos = int(1.0 * rate)
    # Add the CuePoint
    chunk_cue.cue_points.append(CuePoint(id_cue, pos, b"data", 0, 0, pos))
    assocs.append(LabelChunk(id_cue, "First added"))

    # This code works if the fix in [this comment](https://github.com/steelegbr/wave-chunk-parser/issues/174#issuecomment-1712256072) is applied
    # Set the cue marker length to 2x pos 
    assocs.append(LabeledTextChunk(id = id_cue, sample_length = 2*pos,
                                     purpose = '', country = 0, language = 0, dialect = 0, codepage = 0, label = ''))

Does anyone know what I am doing wrong?

Thanks for any tips!, kind regards, Thomas

schittli commented 1 year ago

Good evening

I am pretty sure that this comment solves the problem, because Python no longer creates an Exceptions 😃 and the audio file gets a cue marker with an length > 0 seconds.

Unfortunately, this kind of audio file modification can destroy the audio file structure, therefore someone who knows this Python Module and Python itself should check the fix.

Thanks a lot, kind regards, Thomas