-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from letuananh/dev
refactor media module + add test_data (audio + transcription)
- Loading branch information
Showing
11 changed files
with
966 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea/ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
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 |
---|---|---|
@@ -1,19 +1,37 @@ | ||
from pathlib import Path | ||
import os | ||
from speach import media | ||
from speach import elan | ||
from chirptext import chio | ||
|
||
# ----------------------------------------------------------------------------- | ||
# create a folder to store processed data | ||
# ----------------------------------------------------------------------------- | ||
if not os.path.isdir("./test_data/processed"): | ||
os.mkdir("./test_data/processed") | ||
|
||
ELAN_DIR = Path("~/Documents/ELAN") | ||
|
||
# converting a wave file into an ogg file | ||
media.convert(ELAN_DIR / "test.wav", ELAN_DIR / "test.ogg") | ||
# ----------------------------------------------------------------------------- | ||
# converting the source ogg file into m4a format | ||
# ----------------------------------------------------------------------------- | ||
media.convert("./test_data/fables_01_03_aesop_64kb.ogg", "./test_data/processed/test.m4a") | ||
|
||
# ----------------------------------------------------------------------------- | ||
# cutting audio file by timestamps | ||
media.cut(ELAN_DIR / "test.wav", ELAN_DIR / "test_before10.ogg", to_ts="00:00:10") | ||
media.cut(ELAN_DIR / "test.wav", ELAN_DIR / "test_after15.ogg", from_ts="00:00:15") | ||
media.cut(ELAN_DIR / "test.wav", ELAN_DIR / "test_10-15.ogg", from_ts="00:00:10", to_ts="00:00:15") | ||
# ----------------------------------------------------------------------------- | ||
media.cut("./test_data/processed/test.m4a", "./test_data/processed/test_before_10.ogg", to_ts="00:00:10") | ||
media.cut("./test_data/processed/test.m4a", "./test_data/processed/test_after_10.ogg", from_ts="00:00:15") | ||
media.cut("./test_data/processed/test.m4a", "./test_data/processed/test_10-15.ogg", from_ts="00:00:10", to_ts="00:00:15") | ||
|
||
# Cutting ELAN transcription | ||
eaf = elan.read_eaf(ELAN_DIR / "test.eaf") | ||
for idx, ann in enumerate(eaf["Person1 (Utterance)"], start=1): | ||
eaf.cut(ann, ELAN_DIR / f"test_person1_{idx}.ogg") | ||
# -------------------------------------------------------------------------------------------- | ||
# More complex use case | ||
# Read an ELAN transcription file and: | ||
# 1. Cut all utterances into separated ogg files | ||
# 2. Write annotation text into separated text files | ||
# 3. Write all utterances into a CSV file with annotation IDs and individual audio filenames | ||
# -------------------------------------------------------------------------------------------- | ||
eaf = elan.read_eaf("./test_data/fables_01_03_aesop_64kb.eaf") | ||
csv_rows = [["annID", "Text", "Filename"]] | ||
for ann in eaf["Story"]: | ||
csv_rows.append([ann.ID, ann.text, f"test_{ann.ID}.ogg"]) | ||
chio.write_file(f"./test_data/processed/test_{ann.ID}.txt", ann.text) | ||
eaf.cut(ann, f"./test_data/processed/test_{ann.ID}.ogg") | ||
chio.write_csv("./test_data/processed/test_sentences.csv", csv_rows) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fables_01_03_aesop_64kb.wav | ||
processed/ |
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,6 @@ | ||
# Test data | ||
|
||
Copyright: Both audio and text are in the public domain | ||
|
||
- Audio source: https://librivox.org/aesops-fables-volume-1-fables-1-25/ | ||
- Text source: https://www.gutenberg.org/ebooks/11339 |
Oops, something went wrong.