January 7, 2024, 06:38
py var_1 = 1 var_2 = var_1?
rust use dialoguer::Select; //dialoguer:Select | this let us print options that the user chooses like "buttons", comes handy in this type of program use std::error::Error; use std::io; //standard::input/output | AFAIK this library type let us capture input from the terminal //standard::error::Error | for error handling fn main() -> Result<(), Box<dyn Error>> { // good execution and error handling (Result expect () if everything good and everything else as error) let selection = Select::new() .item("Fahrenheit to Celsius") .item("Celsius to Fahrenheit") .interact()?; //everything else match selection { 0 => convertor(false, "Celsius"), 1 => convertor(true, "Fahrenheit"), _ => return Err("Invalid selection".into()), // everything else returns as error }; Ok(()) } fn convertor(choice: bool, unit: &str) { loop { println!("Input the number to convert"); let mut number = String::new(); // we do not know the value yet io::stdin() .read_line(&mut number) // mutable reference .expect("Failed to read line"); let mut number: f32 = match number.trim().parse() { Ok(num) => num, Err(_) => continue, // this is why we are using a loop, continue skips into the next iteration }; // i could have used promptly :b | update, i do not know how to use promptly match choice { false => number = (number - 32.0) 5.0 / 9.0, //f to c true => number = number 9.0 / 5.0 + 32.0, // c to f } println!("The result is {number:.2}°{unit}"); // .2 in number means 2 decimals after point break; } }
py a = 5 b = 10 a, b = b, a print("a:", a) print("b:", b)
py import speech_recognition as sr recognizer = sr.Recognizer() with sr.Microphone() as source: print("Adjusting noise ") recognizer.adjust_for_ambient_noise(source, duration=1) print("Recording for 10 seconds") recorded_audio = recognizer.listen(source, timeout=10) print("Done recording") try: print("Recognizing the text") text = recognizer.recognize_google( recorded_audio, language="en-US" ) print("Decoded Text : {}".format(text)) except Exception as ex: print(ex) sr.Microphone.list_microphone_names()paste this into thonny and yk talk and see if it works
py import sounddevice as sd from scipy.io.wavfile import write import assemblyai as aai from text_to_speech import save from ctransformers import AutoModelForCausalLM # Sample rate fs = 44100 # Sample rate seconds = 1 # Duration of recording # Replace with your API token aai.settings.api_key = f"c9be33bfb60b41fbaebb13bd8168a639" # URL of the file to transcribe FILE_URL = r"C:\file_path\output.wav"