Skip to content

Commit 66948d9

Browse files
authored
Merge pull request #170 from pettarin/devel
Added regression test for issue #168. Added -f/--full to read_audio
2 parents f36a0da + b9b8831 commit 66948d9

File tree

8 files changed

+70
-2
lines changed

8 files changed

+70
-2
lines changed

aeneas/audiofile.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,12 @@ def __init__(self, file_path=None, file_format=None, rconf=None, logger=None):
209209
self.__samples = None
210210

211211
def __unicode__(self):
212+
fmt = self.file_format
213+
if isinstance(fmt, tuple):
214+
fmt = u"%s %d %d" % fmt
212215
msg = [
213216
u"File path: %s" % self.file_path,
214-
u"File format: %s" % self.file_format,
217+
u"File format: %s" % fmt,
215218
u"File size (bytes): %s" % gf.safe_int(self.file_size),
216219
u"Audio length (s): %s" % gf.safe_float(self.audio_length),
217220
u"Audio format: %s" % self.audio_format,
@@ -644,4 +647,7 @@ def _update_length(self):
644647
This function fails silently if one of the two is ``None``.
645648
"""
646649
if (self.audio_sample_rate is not None) and (self.__samples is not None):
650+
# NOTE computing TimeValue (... / ...) yields wrong results,
651+
# see issue #168
652+
# self.audio_length = TimeValue(self.__samples_length / self.audio_sample_rate)
647653
self.audio_length = TimeValue(self.__samples_length) / TimeValue(self.audio_sample_rate)

aeneas/tests/long_test_task_parameters.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,14 @@ def test_exec_os_task_file_levels_123(self):
354354
("out", "sonnet.json")
355355
], 0)
356356

357+
def test_exec_exact_5600_16000_munparsed_issue_168(self):
358+
self.execute([
359+
("in", "../tests/res/audioformats/exact.5600.16000.wav"),
360+
("in", "../tests/res/inputtext/exact.5600.16000.munparsed.xhtml"),
361+
("", "task_language=eng|is_text_type=munparsed|os_task_file_format=json|is_text_munparsed_l1_id_regex=p[0-9]+|is_text_munparsed_l2_id_regex=p[0-9]+s[0-9]+|is_text_munparsed_l3_id_regex=p[0-9]+s[0-9]+w[0-9]+"),
362+
("out", "sonnet.json")
363+
], 0)
364+
357365

358366
if __name__ == "__main__":
359367
unittest.main()
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="en" xml:lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<meta name="viewport" content="width=768,height=1024"/>
6+
<link rel="stylesheet" href="../Styles/style.css" type="text/css"/>
7+
<title>Sonnet I</title>
8+
</head>
9+
<body>
10+
<div id="divSonnet">
11+
<p class="stanza" id="p000002">
12+
<span id="p000002s000001">
13+
<span id="p000002s000001w000000">1</span>
14+
<span id="p000002s000001w000001">From</span>
15+
<span id="p000002s000001w000002">fairest</span>
16+
<span id="p000002s000001w000003">creatures</span>
17+
<span id="p000002s000001w000004">we</span>
18+
<span id="p000002s000001w000005">desire</span>
19+
<span id="p000002s000001w000006">increase,</span>
20+
<span id="p000002s000001w000007">That</span>
21+
<span id="p000002s000001w000008">thereby</span>
22+
<span id="p000002s000001w000009">beauty’s</span>
23+
<span id="p000002s000001w000010">rose</span>
24+
<span id="p000002s000001w000011">might</span>
25+
<span id="p000002s000001w000012">never</span>
26+
<span id="p000002s000001w000013">die,</span>
27+
</span>
28+
</p>
29+
</div>
30+
</body>
31+
</html>
32+

aeneas/tests/test_audiofile.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class TestAudioFile(unittest.TestCase):
3636
AUDIO_FILE_WAVE = "res/audioformats/mono.16000.wav"
3737
AUDIO_FILE_EMPTY = "res/audioformats/p001.empty"
3838
AUDIO_FILE_NOT_WAVE = "res/audioformats/p001.mp3"
39+
AUDIO_FILE_EXACT = "res/audioformats/exact.5600.16000.wav"
3940
NOT_EXISTING_FILE = "res/audioformats/x/y/z/not_existing.wav"
4041
FILES = [
4142
{
@@ -163,6 +164,11 @@ def test_length(self):
163164
audiofile.clear_data()
164165
self.assertAlmostEqual(audiofile.audio_length, TimeValue("53.3"), places=1) # 53.266
165166

167+
def test_length_exact(self):
168+
audiofile = self.load(self.AUDIO_FILE_EXACT, rs=True)
169+
audiofile.clear_data()
170+
self.assertAlmostEqual(audiofile.audio_length, TimeValue("5.600"), places=3) # 5.600
171+
166172
def test_add_samples_file(self):
167173
audiofile = self.load(self.AUDIO_FILE_WAVE, rs=True)
168174
data = audiofile.audio_samples

aeneas/tests/tool_test_read_audio.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,23 @@ def test_read_audio(self):
5656
("in", "../tools/res/audio.wav")
5757
], 0)
5858

59+
def test_read_audio_full(self):
60+
self.execute([
61+
("in", "../tools/res/audio.wav"),
62+
("", "-f")
63+
], 0)
64+
5965
def test_read_audio_mp3(self):
6066
self.execute([
6167
("in", "../tools/res/audio.mp3")
6268
], 0)
6369

70+
def test_read_audio_mp3_full(self):
71+
self.execute([
72+
("in", "../tools/res/audio.mp3"),
73+
("", "-f")
74+
], 0)
75+
6476
def test_read_audio_path(self):
6577
path = os.path.expanduser("~")
6678
path = os.path.join(path, ".bin/myffprobe")

aeneas/tools/read_audio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ReadAudioCLI(AbstractCLIProgram):
5151
(u"AUDIO_FILE", True)
5252
],
5353
"options": [
54+
u"-f, --full : load samples from file, possibly converting to WAVE"
5455
],
5556
"parameters": [
5657
],
@@ -72,6 +73,8 @@ def perform_command(self):
7273
try:
7374
audiofile = AudioFile(audio_file_path, rconf=self.rconf, logger=self.logger)
7475
audiofile.read_properties()
76+
if self.has_option([u"-f", u"--full"]):
77+
audiofile.read_samples_from_file()
7578
self.print_generic(audiofile.__unicode__())
7679
return self.NO_ERROR_EXIT_CODE
7780
except OSError:

docs/source/changelog.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Changelog
44
v1.7.3 (2017-03-15)
55
-------------------
66

7-
#. Fixed bug #168
7+
#. Fixed bug #168 and added a regression test for it
8+
#. Added option ``-f, --full`` to ``aeneas.tools.read_audio`` and tests for it
89

910
v1.7.2 (2017-03-03)
1011
-------------------

0 commit comments

Comments
 (0)