Skip to content
Snippets Groups Projects
Commit 03bef8ff authored by Blaß, Michael's avatar Blaß, Michael :speech_balloon:
Browse files

Added ``hash`` property to ``AudioFile``.

parent 7025d022
No related branches found
No related tags found
No related merge requests found
Pipeline #6378 passed
......@@ -10,6 +10,7 @@ Functions:
fti16 Cast float to int16.
load_audio Load .wav file.
"""
import hashlib
import pathlib
import matplotlib.pyplot as plt
......@@ -40,6 +41,12 @@ class AudioFile:
"""Return source file name."""
return self._path.name
@property
def hash(self) -> str:
"""Compute sha256 hash."""
obj = hashlib.sha256(self.data.tobytes())
return obj.hexdigest()
@property
def n_channels(self) -> int:
"""Return number of channels."""
......
......@@ -10,6 +10,11 @@ class TestAudioFile(unittest.TestCase):
def test_path_is_sting(self):
self.assertIsInstance(self.snd.file_name, str)
def test_hash(self):
snd2 = AudioFile('audio/beat.wav')
self.assertEqual(self.snd.hash, snd2.hash)
class TestAudioFileReadMono(unittest.TestCase):
def setUp(self):
self.snd = AudioFile('audio/beat.wav')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment