Giter Site home page Giter Site logo

Comments (6)

jstrait avatar jstrait commented on May 24, 2024

@djevo1 the gem doesn't support reading cue/marker points from wave files. I don't think there's a fundamental reason why the gem couldn't support this in the future, but I'm not very familiar with this type of chunk and haven't personally had a reason to use it myself before.

Have you used wave file cue points before? If the gem supported reading cue points from wave files, is there a particular use case you would have in mind?

from wavefile.

zoras avatar zoras commented on May 24, 2024

@jstrait I was looking for the same as I want to split a portion of the wave file. BTW how do I split wave file? I didn't find any example for splitting files.

from wavefile.

jstrait avatar jstrait commented on May 24, 2024

@zoras can you say more about how you are wanting to split the file? Are you wanting to split it based on cue/marker points? Or some different way? What is the bigger thing you are trying to accomplish by splitting the file? (Just asking because it might help me give a better answer).

As an example, if you wanted to split a file so that every 100,000 samples went to a different file, this is one way you could do it:

require 'wavefile'
include WaveFile

SAMPLE_FRAMES_PER_FILE = 100000
OUTPUT_FORMAT = Format.new(:stereo, :pcm_16, 44100)

file_name = "input_file.wav"
file_index = 1

Reader.new(file_name).each_buffer(SAMPLE_FRAMES_PER_FILE) do |buffer|
  Writer.new("output_file_#{file_index}.wav", OUTPUT_FORMAT) do |writer|
    writer.write(buffer)
  end

  file_index += 1
end

from wavefile.

zoras avatar zoras commented on May 24, 2024

@jstrait I am working with wavefile and wanted to trim the audio file let's say of 10:00 minutes from 3:00 to 7:00 mins. At the moment, I'm using audio-trimmer to accomplish the same.

from wavefile.

jstrait avatar jstrait commented on May 24, 2024

@zoras there's not a direct way to do that, but you could do it like this:

  1. Read sample frames (but throw them away) until you reach the starting trim point
  2. Next, read sample frames until the ending trim point, and write them to the output file.

For example, something like this:

require 'wavefile'
include WaveFile

STARTING_NUMBER_OF_SECONDS = 3 * 60   # Starting point is 3 minutes into file
ENDING_NUMBER_OF_SECONDS = 7 * 60     # Ending point is 7 minutes into file

Reader.new("file_to_trim.wav") do |reader|
  STARTING_SAMPLE_FRAME = reader.format.sample_rate * STARTING_NUMBER_OF_SECONDS
  ENDING_SAMPLE_FRAME = reader.format.sample_rate * ENDING_NUMBER_OF_SECONDS

  # Read up to the starting trim point
  throwaway_buffer = reader.read(STARTING_SAMPLE_FRAME)

  Writer.new("trimmed_file.wav", reader.format) do |writer|
    buffer = reader.read(ENDING_SAMPLE_FRAME - STARTING_SAMPLE_FRAME)
    writer.write(buffer)
  end
end

Hope that helps!

from wavefile.

henrikj242 avatar henrikj242 commented on May 24, 2024

I just added loop information extraction in another project. I've forked this repo and expect to implement the same here :)

from wavefile.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.