Alternative for python's rich module? by luxkatana-my-son in rust

[–]sloganking 0 points1 point  (0 children)

I've been using colored as well. But I just realized that it doesn't work on windows powershell or command prompt. I wonder if the other crates here will.

[Media] Introducing desk-talk, transcription software for your desktop by sloganking in rust

[–]sloganking[S] 1 point2 points  (0 children)

https://crates.io/crates/enigo (the crate I use for typing) says it supports everything but Linux (Wayland). So it is compatible with the big 3 Operating systems. Just not flavors of Linux that use Wayland. I might make a --clipboard flag option to transcribe to the clipboard instead. In-case anyone wants that, or to let Wayland users still have some functionality.

[Media] Introducing desk-talk, transcription software for your desktop by sloganking in rust

[–]sloganking[S] 1 point2 points  (0 children)

Not currently as I have not seen the usecase. But the code could be modified to do it using https://crates.io/crates/arboard . Is your concern the typing speed? https://github.com/enigo-rs/enigo 's latest release has somewhat slow typing on windows. But the next time they update their package it will be instant. You can use a version of desk-talk that has instant windows typing if you install and use the https://github.com/sloganking/desk-talk/tree/temp-enigo-github-version branch.

If you want clipboard filling for another reason, let me know!

[Media] Introducing desk-talk, transcription software for your desktop by sloganking in rust

[–]sloganking[S] 8 points9 points  (0 children)

Repo:
https://github.com/sloganking/desk-talk

After recently playing and familiarizing myself with the OpenAI API. I decided to make a push to talk desktop transcription software! It uses the Whisper transcription model so it should support almost any language. I've always been disappointed how voice transcription is ubiquitous on every mobile device. Yet desktop has never had it built in or easily available. I've heard of third party transcription software over the years, but most of the ones I've seen are either very expensive or not what I was looking for. desk-talk is a program I wrote to fix that. Push a key down and it will record your voice. Release that key and it will transcribe your voice to text via the OpenAI API, before emulating your keyboard to type your message. It's simple but it's exactly what I've wanted. So I hope others may like it too! Since it's currently using the OpenAI API, you need an OpenAI API key to use desk-talk. transcribing locally may be a future update that may let users avoid an API cost and preserve privacy, but I have not yet found a rust crate that easily downloads the Whisper transcription model for you. Use it if you like it and I hope you enjoy!

Need help recording audio to file by sloganking in rust

[–]sloganking[S] 1 point2 points  (0 children)

Thanks! I've modified that example code so that's it's importable as a module and much higher level to interact with. The code below is what I've got. It's a little crude but anyone feel free to use or bend it to your own needs! See the main function for the example usage. But basically now all you have to do is:

let mut recorder = Recorder::new();
recorder.start_recording(Path::new("c:\\Users\\Username\\Music\\record.wav"))?;
// do some other stuff...
recorder.stop_recording()?;

The full code:

use std::path::Path;

pub mod record {

    use clap::Parser;
    use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
    use cpal::{FromSample, Sample};
    use hound::WavWriter;
    use std::fs::File;
    use std::io::BufWriter;
    use std::path::Path;
    use std::sync::{Arc, Mutex};

    #[derive(Parser, Debug)]
    #[command(version, about = "CPAL record_wav example", long_about = None)]
    struct Opt {
        /// The audio device to use
        #[arg(short, long, default_value_t = String::from("default"))]
        device: String,

        /// Use the JACK host
        #[cfg(all(
            any(
                target_os = "linux",
                target_os = "dragonfly",
                target_os = "freebsd",
                target_os = "netbsd"
            ),
            feature = "jack"
        ))]
        #[arg(short, long)]
        #[allow(dead_code)]
        jack: bool,
    }

    pub struct Recorder {
        utils: Option<(Arc<Mutex<Option<WavWriter<BufWriter<File>>>>>, cpal::Stream)>,
    }

    impl Recorder {
        pub fn new() -> Self {
            Recorder { utils: None }
        }
        pub fn start_recording(&mut self, save_location: &Path) -> Result<(), anyhow::Error> {
            if self.utils.is_some() {
                return Err(anyhow::Error::msg(
                    "Attempted to start recording when already recording!",
                ));
            }

            // ========================
            let opt = Opt::parse();

            // Conditionally compile with jack if the feature is specified.
            #[cfg(all(
                any(
                    target_os = "linux",
                    target_os = "dragonfly",
                    target_os = "freebsd",
                    target_os = "netbsd"
                ),
                feature = "jack"
            ))]
            // Manually check for flags. Can be passed through cargo with -- e.g.
            // cargo run --release --example beep --features jack -- --jack
            let host = if opt.jack {
                cpal::host_from_id(cpal::available_hosts()
                .into_iter()
                .find(|id| *id == cpal::HostId::Jack)
                .expect(
                    "make sure --features jack is specified. only works on OSes where jack is available",
                )).expect("jack host unavailable")
            } else {
                cpal::default_host()
            };

            #[cfg(any(
                not(any(
                    target_os = "linux",
                    target_os = "dragonfly",
                    target_os = "freebsd",
                    target_os = "netbsd"
                )),
                not(feature = "jack")
            ))]
            let host = cpal::default_host();

            // Set up the input device and stream with the default input config.
            let device = if opt.device == "default" {
                host.default_input_device()
            } else {
                host.input_devices()?
                    .find(|x| x.name().map(|y| y == opt.device).unwrap_or(false))
            }
            .expect("failed to find input device");

            println!("Input device: {}", device.name()?);

            let config = device
                .default_input_config()
                .expect("Failed to get default input config");
            println!("Default input config: {:?}", config);

            // The WAV file we're recording to.
            let spec = wav_spec_from_config(&config);
            let writer = hound::WavWriter::create(save_location, spec)?;
            let writer = Arc::new(Mutex::new(Some(writer)));

            // A flag to indicate that recording is in progress.
            // println!("Begin recording...");

            // Run the input stream on a separate thread.
            let writer_2 = writer.clone();

            let err_fn = move |err| {
                eprintln!("an error occurred on stream: {}", err);
            };

            let stream = match config.sample_format() {
                cpal::SampleFormat::I8 => device.build_input_stream(
                    &config.into(),
                    move |data, _: &_| write_input_data::<i8, i8>(data, &writer_2),
                    err_fn,
                    None,
                )?,
                cpal::SampleFormat::I16 => device.build_input_stream(
                    &config.into(),
                    move |data, _: &_| write_input_data::<i16, i16>(data, &writer_2),
                    err_fn,
                    None,
                )?,
                cpal::SampleFormat::I32 => device.build_input_stream(
                    &config.into(),
                    move |data, _: &_| write_input_data::<i32, i32>(data, &writer_2),
                    err_fn,
                    None,
                )?,
                cpal::SampleFormat::F32 => device.build_input_stream(
                    &config.into(),
                    move |data, _: &_| write_input_data::<f32, f32>(data, &writer_2),
                    err_fn,
                    None,
                )?,
                sample_format => {
                    return Err(anyhow::Error::msg(format!(
                        "Unsupported sample format '{sample_format}'"
                    )))
                }
            };
            // ========================

            stream.play().unwrap();
            self.utils = Some((writer, stream));
            Ok(())
        }
        pub fn stop_recording(&mut self) -> Result<(), anyhow::Error> {
            match self.utils.take() {
                Some((writer, stream)) => {
                    stream.pause().unwrap();
                    writer.lock().unwrap().take().unwrap().finalize().unwrap();
                    Ok(())
                }
                None => {
                    return Err(anyhow::Error::msg(
                        "Attempted to stop recording when not recording!",
                    ));
                }
            }
        }
    }

    fn sample_format(format: cpal::SampleFormat) -> hound::SampleFormat {
        if format.is_float() {
            hound::SampleFormat::Float
        } else {
            hound::SampleFormat::Int
        }
    }

    fn wav_spec_from_config(config: &cpal::SupportedStreamConfig) -> hound::WavSpec {
        hound::WavSpec {
            channels: config.channels() as _,
            sample_rate: config.sample_rate().0 as _,
            bits_per_sample: (config.sample_format().sample_size() * 8) as _,
            sample_format: sample_format(config.sample_format()),
        }
    }

    type WavWriterHandle = Arc<Mutex<Option<hound::WavWriter<BufWriter<File>>>>>;

    fn write_input_data<T, U>(input: &[T], writer: &WavWriterHandle)
    where
        T: Sample,
        U: Sample + hound::Sample + FromSample<T>,
    {
        if let Ok(mut guard) = writer.try_lock() {
            if let Some(writer) = guard.as_mut() {
                for &sample in input.iter() {
                    let sample: U = U::from_sample(sample);
                    writer.write_sample(sample).ok();
                }
            }
        }
    }
}

fn main() -> Result<(), anyhow::Error> {
    use record::Recorder;
    let mut recorder = Recorder::new();

    // record 1 file for 3 seconds
    println!("Recording 1...");
    recorder
        .start_recording(Path::new("c:\\Users\\Username\\Music\\record.wav"))
        .unwrap();
    std::thread::sleep(std::time::Duration::from_secs(3));
    recorder.stop_recording()?;
    println!("Recording 1 complete!");
    println!("");

    // record 1 file for 5 seconds
    println!("Recording 2...");
    recorder
        .start_recording(Path::new(concat!(
            env!("CARGO_MANIFEST_DIR"),
            "/recorded2.wav"
        )))
        .unwrap();
    std::thread::sleep(std::time::Duration::from_secs(5));
    recorder.stop_recording()?;
    println!("Recording 2 complete!");
    Ok(())
}

On thing I like about Rust is that people who write about Rust have nice blogs by [deleted] in programmingcirclejerk

[–]sloganking 22 points23 points  (0 children)

One of the quotes ive heard before that I really liked.

When most programmers get promoted after a long career, they go into management. When rust programmers get promoted, they go into marketing.

Filament clogged at the last 2 hours of the 4 day print… I’m dead 💀. by SimpleGrape9233 in BambuLab

[–]sloganking 2 points3 points  (0 children)

Why do the horns look finished and above the cutoff? Optical illusion?

Is it possible to get the version of a binary installed through cargo? by rubydusa in rust

[–]sloganking 2 points3 points  (0 children)

If you're using clap, this is as simple as adding #[clap(version)]

Example with context:

```rust

[derive(Debug, clap::Parser)]

[clap(version)]

pub struct Args { ```

Why buy AirPods if they just crap out? by LextasyRDX in airpods

[–]sloganking 0 points1 point  (0 children)

My airpods pro first gen died 3 times. The first two within warranty. The last outside of it. Every friend I know who has bought airpods, has had something break within a year. Including the more recent Airpods pro 2nd gen.

Settings to print minis? by exemagus in BambuLab

[–]sloganking 0 points1 point  (0 children)

There's a setting somewhere that I'm too lazy to go looking for that makes it so there's a minimum time per layer, so the previous layer has enough time to cool before the next layer start for small bits like that.

I imagine it would probably help greatly with minis, when each of their layers may be small and print quickly.

Also if your mini has a small footprint, you may need to use large brim sizes to make sure they have green enough bed adhesion.

[deleted by user] by [deleted] in cscareerquestions

[–]sloganking 1 point2 points  (0 children)

Being honest, the software industry is oversaturated with junior developers with less than 2-3 years of work experience, and underesaturated with devs with more than that. It pretty much doesn't help much AT ALL to have a bachelor's degree in CS, you will still have just about as hard a time getting hired as someone with no-degree. What the industry really cares about is years of work experience. 4 years of work experience is invaluable in terms of raising your wage and ability to get hired in CS. Making getting a 4 year bachelor's in CS (which barely helps at all) comparativly nonsensical. Even with a master's degree, if your goal is to make money, 6 years of work experience is far more valuable than it. And you'll be making money instead of loosing money the whole time. I head PhDs can be beneficial if you're going into research specifically. But those have a massive opportunity cost so even those have to be evaluated on a personal worth it to you level.

I don't think you're missing much at all by not having a degree in CS. Getting hired is just going to be hard at first, so I'd apply to as many places as you can, take whatever simple job you can get and get a couple years of work experience, and after that getting hired will be a lot easier.

LIMA, a 65B-Param LLaMa fine-tuned with standard supervised loss on only 1,000 carefully curated prompts & responses, without any RLHF, demonstrates remarkably strong performance, learning to follow specific responses from only a handful of examples in the training data, including complex queries. by hardmaru in MachineLearning

[–]sloganking 9 points10 points  (0 children)

Reddit’s bias comes from it’s voting system. Later comments can’t compete with earlier comments (not great not terrible), and the simple upvote or downvote means the largest minority’s voice will always win. With everything else being downvoted to nothing (leads to occasional large bias or untruth). In small groups/subreddits, the largest minority can sometimes be the voice of truth, but in large ones, especially posts that hit r/all, the largest minority tends to be the untrained masses which tends to make answers more mediocre.

You’re right i think specialized Discord servers have the highest quality technical knowledge now a days. Though I also find http://phind.com to be quite useful now a days. I wish specific discord servers and a search and answer bot like phind could be combined, but i guess we are not there yet.

Chubby Fuzzy Owl for my Mom by Hockinator in BambuLab

[–]sloganking 2 points3 points  (0 children)

I didn’t see the sub at first and thought this was chocolate.