-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
132 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/id/ac/itb/lumen/sinsymaker/Segment2WordsApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package id.ac.itb.lumen.sinsymaker; | ||
|
||
import be.tarsos.dsp.AudioDispatcher; | ||
import be.tarsos.dsp.io.TarsosDSPAudioFormat; | ||
import be.tarsos.dsp.io.jvm.AudioDispatcherFactory; | ||
import com.google.common.base.Splitter; | ||
import org.apache.commons.io.FilenameUtils; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
@SpringBootApplication | ||
@Profile("segment2words") | ||
public class Segment2WordsApp implements CommandLineRunner { | ||
|
||
public static void main(String[] args) { | ||
new SpringApplicationBuilder(Segment2WordsApp.class) | ||
.profiles("segment2words") | ||
.run(args); | ||
} | ||
|
||
@Override | ||
public void run(String... args) throws Exception { | ||
final TarsosDSPAudioFormat format = new TarsosDSPAudioFormat(44100, 16, 1, true, false); | ||
final File clauseAudioFile = new File("/together/project_amanah/lumen/speech/expressive/clauses/perangkap oleh.wav"); | ||
final File targetDir = new File("/together/project_amanah/lumen/speech/expressive/words"); | ||
targetDir.mkdirs(); | ||
|
||
final String clause = FilenameUtils.getBaseName(clauseAudioFile.getName()); | ||
final List<String> splitClause = Splitter.on(' ').splitToList(clause); | ||
double estMedianPos = splitClause.get(0).length() * 1d / (splitClause.get(0).length() + splitClause.get(1).length()); | ||
|
||
final AudioDispatcher dispatcher = AudioDispatcherFactory.fromFile(clauseAudioFile, 2048, 0); | ||
long estMedianFrame = Math.round(estMedianPos * dispatcher.durationInFrames()); | ||
final int ATTACK_MS = 500; | ||
final int RELEASE_MS = 500; | ||
final int attackFrames = Math.round(ATTACK_MS / 1000f * format.getSampleRate()); | ||
final int releaseFrames = Math.round(RELEASE_MS / 1000f * format.getSampleRate()); | ||
// with attack + release | ||
dispatcher.addAudioProcessor(new SegmentWaveformWriter(format, new File(targetDir, splitClause.get(0) + ".wav").getPath(), | ||
0, estMedianFrame + releaseFrames, attackFrames, releaseFrames)); | ||
dispatcher.addAudioProcessor(new SegmentWaveformWriter(format, new File(targetDir, splitClause.get(1) + ".wav").getPath(), | ||
estMedianFrame - attackFrames, dispatcher.durationInFrames(), attackFrames, releaseFrames)); | ||
// strict splitter | ||
// dispatcher.addAudioProcessor(new SegmentWaveformWriter(format, new File(targetDir, splitClause.get(0) + ".wav").getPath(), | ||
// attackFrames, estMedianFrame, 0, 0)); | ||
// dispatcher.addAudioProcessor(new SegmentWaveformWriter(format, new File(targetDir, splitClause.get(1) + ".wav").getPath(), | ||
// estMedianFrame, dispatcher.durationInFrames() - releaseFrames, 0, 0)); | ||
dispatcher.run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters