"pkg-config",
]
+[[package]]
+name = "atty"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+dependencies = [
+ "hermit-abi",
+ "libc",
+ "winapi",
+]
+
[[package]]
name = "autocfg"
version = "1.1.0"
"libloading",
]
+[[package]]
+name = "clap"
+version = "3.2.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "44bbe24bbd31a185bc2c4f7c2abe80bea13a20d57ee4e55be70ac512bdc76417"
+dependencies = [
+ "atty",
+ "bitflags",
+ "clap_derive",
+ "clap_lex",
+ "indexmap",
+ "once_cell",
+ "strsim",
+ "termcolor",
+ "textwrap",
+]
+
+[[package]]
+name = "clap_derive"
+version = "3.2.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9ba52acd3b0a5c33aeada5cdaa3267cdc7c594a98731d4268cdc1532f4264cb4"
+dependencies = [
+ "heck",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "clap_lex"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
+dependencies = [
+ "os_str_bytes",
+]
+
[[package]]
name = "claxon"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
+[[package]]
+name = "hashbrown"
+version = "0.12.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
+
+[[package]]
+name = "heck"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
+
+[[package]]
+name = "hermit-abi"
+version = "0.1.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
+dependencies = [
+ "libc",
+]
+
[[package]]
name = "hound"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
+[[package]]
+name = "indexmap"
+version = "1.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
+dependencies = [
+ "autocfg",
+ "hashbrown",
+]
+
[[package]]
name = "instant"
version = "0.1.12"
name = "line_audiolizer"
version = "0.1.0"
dependencies = [
+ "clap",
"rodio",
"unicode-width",
]
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
+[[package]]
+name = "os_str_bytes"
+version = "6.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4"
+
[[package]]
name = "parking_lot"
version = "0.11.2"
"toml",
]
+[[package]]
+name = "proc-macro-error"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
+dependencies = [
+ "proc-macro-error-attr",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro-error-attr"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "version_check",
+]
+
[[package]]
name = "proc-macro2"
version = "1.0.42"
"unicode-ident",
]
+[[package]]
+name = "termcolor"
+version = "1.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
+dependencies = [
+ "winapi-util",
+]
+
+[[package]]
+name = "textwrap"
+version = "0.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
+
[[package]]
name = "thiserror"
version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
+[[package]]
+name = "version_check"
+version = "0.9.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
+
[[package]]
name = "walkdir"
version = "2.3.2"
[dependencies]
unicode-width = "0.1.9"
rodio = "0.15.0"
+clap = { version = "3.2.15", features = ["derive"] }
# Line Audiolizer
Turn lines of code (or text files) into sound, written in Rust.
-Prints stdin, playing a tone for each line. The pitch of the tone depends on the length (or rather, UTF-8 width) of the line. Tabs count as 8 spaces.
+Prints stdin, playing a sine wave tone for each line. The pitch of the tone depends on the length (or rather, UTF-8 width) of the line.
Idea by [scplusplus](https://github.com/scplusplus).
```sh
cargo run < src/main.rs | batcat --paging never --language rust
```
+
+For available options, see:
+```sh
+cargo run -- --help
+```
+use std::{io::{self, Write}, time::Duration};
use unicode_width::UnicodeWidthStr;
-use std::io::Write;
+use rodio::{OutputStream, Sink, source::{SineWave, Source}};
+use clap::Parser;
-use std::time::Duration;
-use rodio::{OutputStream, Sink};
-use rodio::source::{SineWave, Source};
+#[derive(Parser, Debug)]
+#[clap(version, about, long_about = None)]
+struct Args {
+ /// How many spaces a tab character counts as
+ #[clap(short, long, value_parser, default_value_t = 4)]
+ tab_width: usize,
+
+ /// Frequency of tones. Multiplied by line length
+ #[clap(short, long, value_parser, default_value_t = 20.0)]
+ frequency: f32,
+
+ /// Duration of each tone, in seconds
+ #[clap(short, long, value_parser, default_value_t = 0.1)]
+ duration: f32,
+
+ /// Amplifier of tones
+ #[clap(short, long, value_parser, default_value_t = 1.0)]
+ amplifier: f32,
+}
fn main() {
+ let args = Args::parse();
+
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
let sink = Sink::try_new(&stream_handle).unwrap();
- let mut stdout = std::io::stdout().lock();
+ let mut stdout = io::stdout().lock();
- for line in std::io::stdin().lines() {
+ for line in io::stdin().lines() {
let line: String = line
.unwrap()
.chars()
- .map(|c| if c == '\t' { String::from(" ").repeat(8) } else { c.to_string() })
+ .map(|c|
+ if c == '\t' {
+ String::from(" ").repeat(args.tab_width)
+ } else {
+ c.to_string()
+ }
+ )
.collect();
let len = UnicodeWidthStr::width(&*line) as f32;
stdout.write_fmt(format_args!("{}\n", line)).unwrap();
- sink.append(SineWave::new(44.0 * len)
- .take_duration(Duration::from_secs_f32(0.1))
- .amplify(0.20));
+ sink.append(SineWave::new(args.frequency * len)
+ .take_duration(Duration::from_secs_f32(args.duration))
+ .amplify(args.amplifier));
sink.sleep_until_end();
}
}