commit f6e2bb89e9e1ab675c3c261d64c9eb227179788f Author: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Mon Jun 17 18:16:18 2024 +0200 feat: Add first working example diff --git a/main.py b/main.py new file mode 100644 index 0000000..827a2a6 --- /dev/null +++ b/main.py @@ -0,0 +1,59 @@ +import wave +import array +import random + +SPLIT_PARTS = 5 + + +def transpose_parts(parts: list[int]): + parts_copy = parts.copy() + + parts[0] = parts_copy[2] + parts[1] = parts_copy[0] + parts[2] = parts_copy[4] + parts[3] = parts_copy[3] + parts[4] = parts_copy[1] + + +def main() -> None: + # Type _raw_wavefile as wave_read + with wave.open("./lasttime.wav") as _raw_wavefile: + with wave.open("output.wav", mode="wb") as write_file: + wave_file: wave.Wave_read = _raw_wavefile + + metadata = wave_file.getparams() + first_frame = wave_file.readframes(1) + raw_frames = wave_file.readframes(metadata.nframes) + + frames = array.array("h", raw_frames) + + write_file.setnchannels(1) + write_file.setsampwidth(metadata.sampwidth) + write_file.setframerate(metadata.framerate) + + + # Iterate over seconds + for i in range(0, int(metadata.nframes / 2), metadata.framerate): + second = frames[i:i + metadata.framerate] + + # Split the second into parts + second_part_duration = int(metadata.framerate / SPLIT_PARTS) + + parts = [ + second[(j * second_part_duration):(j * second_part_duration) + second_part_duration] + for j in range(0, SPLIT_PARTS + 1 ) + ] + + #random.shuffle(parts) + transpose_parts(parts) + + new_second = [] + + for part in parts: + new_second.extend(part) + + write_file.writeframes(array.array("h", new_second).tobytes()) + + +if __name__ == "__main__": + main() diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..bcf4ea8 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,17 @@ +# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. + +[[package]] +name = "wave" +version = "0.0.2" +description = "Whole Architecture Verification" +optional = false +python-versions = "*" +files = [ + {file = "Wave-0.0.2.tar.gz", hash = "sha256:5a895bb85e04e38c82dba90d66a5ae8f488b50c58f3fc4df868a5bcdcabb8632"}, + {file = "Wave-0.0.2.zip", hash = "sha256:5187f49497287d218cc83d4cd1e5299dc31485ab3ed32abbaa9e95d8f73c4095"}, +] + +[metadata] +lock-version = "2.0" +python-versions = "^3.10" +content-hash = "941eaca5ccecefc43101974a6e38157b3545230205b83688a419939d8140fe63" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b040299 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,16 @@ +[tool.poetry] +name = "time-scrambler" +version = "0.1.0" +description = "" +authors = ["Myzel394 <50424412+Myzel394@users.noreply.github.com>"] +readme = "README.md" +# packages = [{include = "time_scrambler"}] + +[tool.poetry.dependencies] +python = "^3.10" +Wave = "^0.0.2" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api"