Categories
Batch Coding StuffBuild

Stuffbuild: All WAV to MP3 Right-click Converter for Windows

Updated 02/05/2021

Behold, Windows users:  “Convert All WAV to MP3”!

WAV TO MP3 Converter demonstration
Sorry Unix ppl

A simple, lazy script that will save you a trip to Audacity… or even possibly a simpler method. 🙃

This dead-simple script does one thing quite well: it converts all WAV files in the directory you right-click in to MP3, non-recursively. (I do mention a recursive version below, with a caveat.)

A warning before we get into this tutorial: we will be editing registries. If that doesn’t scare you, I nonetheless advise you to back them up in case something goes wrong.

Let’s dive in.

JonOfOz Splash

(If you don’t care why I made this, click here for the tutorial.)

The why

You may have read in my About page that I was in an Irish band for 7.5 years; now, I’m starting up an experimental Irish jam. You can read about it in a future article, probably! 🤞

This jam will be a fusion of live musicians and live tech. Part of this process currently involves me making a lot of tracks for a lot of tunes that

  1. need to be played back live, and
  2. need to be available for jam members on a private Drive for the sake of practice and/or reference.
The problem

I’m using FL Studio to export these tracks: as far as I’m aware, FL Studio can only export playlist tracks as WAV files, at least currently.

A brief aside: WAV files are “lossless” (more data), and as a result can quickly eat up space on the Drive. Also, because of their higher data density, they take longer times to load, the effect being particularly noticeable on poor connections, which I would rather assume most people have; MP3 files are “lossy” (less data), so they load faster and are more compact. And hey, you can upload waaaaay more MP3 tracks to a Drive than WAV files!

The solution
  • A batch script with some techno-voodoo
  • Some mucking around in the registries
  • The LAME encoder
  • A lot of tutorials / references for those three

FWIW, I had absolutely never done anything like this before, and now I feel dangerously empowered. ⚡⌨

Editing the Registries

I only needed to edit HKEY_CLASSES_ROOT\Directory\Background\shell. This is where Windows looks for context-menu items (when no items are selected).

I simply added the Convert All WAV to MP3 key, making it available instantly, and then another key within, command, which fires the batch script, which we’ll make next.

Editing the registries
The Batch Script

First, create a batch (.bat) file in a reliable place where you expect it to remain (i.e. where it is less prone to link rot). It doesn’t matter what you name it: just name it sensibly.

As you can see above, mine is located at "C:\Users\lordd\Desktop# CODE\BAT\ConvertAllWAVToMP3.bat".

Now, here’s what’s inside!

mkdir MP3Conversions
for %%I in ("*.wav") do lame "%%I" "MP3Conversions/%%~nI.mp3"
pause

Okay, so what’s going on here?

  1. We make the directory MP3Conversions.
  2. We iterate over each *.wav file in the directory in which you right-clicked, making a call to the lame encoder. (We’ll set that up later, don’t worry.) The first argument is wrapped in double quotes; the second argument is also wrapped in double quotes, but the ~n flag causes the extension to be dropped, and we just toss .mp3 onto the end. (Again, it will only convert WAV files in this directory, and none in any nested folders.)
  3. Pause, JIC you need to inspectigate; remove this line if you don’t.

Note that I chose %%I arbitrarily: you could use another single letter, upper or lower case, and get the same result. However, variables are case sensitive, so consistency matters!

If you want to do this recursively (i.e find WAV files in nested directories), then change
for %%I in
to
for /R %%I in
The one caveat here is that any files with identical names will overwrite each other. So make sure your files are named uniquely at all levels!

The Lame Encoder

I downloaded a compiled, OS + architecture appropriate version of the LAME encoder from this page at RareWares. Since I have a 64bit version of Windows 10, I downloaded the one that says “Download x64 bundle(1214kB)“. Make sure you have at least these two files: lame.exe and lame_enc.dll.

I tossed them all (plus a free doc folder) in C:\lame, but you could place them somewhere else.

Location of LAME encoder


And then I added the folder’s PATH to my environment variables.

Setting PATH variable

Bear in mind, that PATH should reflect where you placed your copy of the LAME, whether it’s in C:\lame like mine or somewhere else! Also, make sure you do not have a trailing slash ( \ ) at the end.

And that’s all there is to it! 😀 This was a fun project for me, and it’s definitely got me wondering what I can do next with little scripts like these. Hopefully this helps you do the same!

Categories
Coding TheMoreYouKnow What Is - X

WHAT IS – STATIC TYPING?

Updated 11/2/2020

The Gist of Static Typing

More languages today are based around Static Typing than Dynamic Typing. There are some languages that support both, but we won’t get into that here.
While statically-typed languages usually run faster than their dynamic brethren, they’re less trendy in the realm of web development and data science, although WebAssembly has been looking to shake up that game a bit. In general, these languages are better suited for games and applications, and won’t be going away any day soon!

Statically-typed languages are typically not beginner friendly, but that doesn’t mean they aren’t worth learning. Let’s jump in.

What is Static Typing?

It’s a little like this: Static Typing is a method where all variables must have a type, and that type cannot be changed during runtime.

Before we get confused here: the values of these static variables can change! They’re not like constants, whose values can’t change (and whose data types also can’t change, but I digress).

The only caveat is, quite predictably, that any new value assigned to the variable must be of the same type as the last value.


// In C++, we define a variable myInt of type int.
int myInt = 7; 

// This reassignment to another int value is okay!
myInt = 8; 

// This reassignment to a String is no good.
myInt = "JonOfOz";

Type checking happens at compile time. The compiler first verifies that the code doesn’t break any type rules, and if not, the program runs. Else, you’ll get type errors you need to fix first. This doesn’t guarantee you won’t run into errors, but you won’t run into ones related to type.

Static Typing has a number of benefits:
  • Static Typing results in faster, leaner code, since all data types are declared and checked at compile time.
  • There is less chance of running into errors in the middle of long processes due to simple mistakes. Imagine running a process that takes two days to finish, then bam, the code fails at hour 46 due to a single line where an integer was expected, but the string version of that integer gotassigned, and everything fell apart. Ouch.
Static Typing also has drawbacks:
  • Debugging can be frustrating in and of itself; that’s even more so the case with statically typed languages. The error messages can be pretty vague, and you’re dead in the water if you can’t start your debugger until you compile your code… which can’t compile until you fix all of the bugs. (You can get around this, but it can be a pain.)
  • Static typing is like an overprotective parent. If it sees you are about to learn a harsh lesson due to a type error, it won’t have it. This sort of sounds great, but giving the developer guardrails isn’t always a win: we learn a great deal from failures. So, what happens when we fail less?

How Does Static Typing Compare to Dynamic Typing?

For variables of both statically-typed and dynamically-typed languages, one principle is the same: whatever those variables are, they are references to addresses in memory.
In the case of the statically-typed example above, it’s referencing 7— more accurately, the memory address represented by 7.

The differences lies in the variables.

Static Typing

When a variable like myInt is declared, it is bound to the int data type for the duration of the runtime. The variable calls the shots: if it starts out as an int and you try to assign it a new String value, you’ll get an error.

Dynamic Typing

When a variable like myInt is declared, it’s nothing more than a reference to some address in memory. It might represent None / null, it might be an int, a String, it doesn’t matter. As long as you don’t perform illegal operations on whatever type it is at any point in runtime, you’re good to go.

Categories
Coding TheMoreYouKnow What Is - X

WHAT IS – PYTHON?

Updated 10/20/2020

The Gist of Python

I won’t hide it: Python is my favorite programming language of all time.


No, it’s not the fastest language out there—you’re not going to find it powering Triple A games or any graphics-intensive applications any time soon—but it can basically do everything really well and in fewer lines of code than other languages. And, in terms of readability and functionality, it hits a bullseye.

We won’t go into Python’s history here: there’s Wikipedia for that. I want to briefly explain what Python is, what makes it stand apart from most languages, and where it’s being used today. Let’s jump in.

What Python Is

Python is a programming language that is dead easy to learn, beautiful to look, and widely used—hey, you might be surprised where.

For starters, have some Python code!

> def say_hi():
>     print("Hello World!")
> hi()
"Hello World!"

Obviously, we could get more complex than that. Here, we just define a function and then we run it.

I just wanted to give a simple example to demonstrate the fact: Python is simple. So much so, it’s the most popular introductory programming language taught in universities worldwide.
The aforementioned study was done in 2014, but the momentum certainly hasn’t stopped. Udemy straight up advertises Python (above Javascript no less!) in their app store description. A large number of the most popular courses on Udemy are about Python and/or prominently feature Python as the language of choice for a number of different applications.

Udemy knows what you really want.

That leads us to another point: Python is general purpose. It can be used for creating websites and web apps; it can be crammed into integrated systems; and for Pete’s sake, it can power a Raspberry Pi to water your poor houseplants as you watch indifferently. Python is also popular for API development.

Where Python really excels, however, is in the realm of science.

Powerful libraries like Pandas, NumPy, SciPy, MatplotLib, Seaborn, Tensorflow, and others make data analysis, linear algebra, spreadsheet manipulation, and machine learning accessible (and relatively easy) to the general public by combining Python’s syntatic simplicity with common functions and routines found in each discipline.

What Makes Python Unique

Arguably the most unique thing about Python—and usually a dead giveaway that you’re looking at Python code—is its strict usage of indentation. By this, Python is said to adhere to the Off-side rule, a rarity among programming languages, with less than 2% of all languages using significant indentation.

Unlike the multifarious compiled languages, Python is an interpreted language: without going into the nitty-gritty details, this means code is compiled at runtime, not before. An implication of this is that your Python code doesn’t necessarily need to be error-free before you can run it, although Python won’t execute if, say, your code indentation is incorrect. which is a luxury you won’t get in a compiled language like C / C++ or Java something Compiled languages must be free: they won’t run if there is an error anywhere in the code

Where Python is Used Today

Forthcoming lol

Categories
Coding Python Secrets TheMoreYouKnow

The Arcane Secrets Of – PYTHON

Updated 10/13/2020

What We’ll Cover

  1. Various features in Python you may not have known about!
  2. These various features in action!
  3. Russian Roulette!

What We Won’t Cover

  1. Whether or not these features are considered by best practice.
  2. These features in both Python 2 and 3 (This site only covers 3).
  3. Any expenses related to playing Russian Roulette.
  • while loops and for loops can have else statements!
# RUSSIAN ROULETTE - Let's Play!
# (Seriously, don't.)
chamber_with_bullet = random.randint(1,6)
game_rounds = 3
dead = False
while not dead:
    # Spin the chamber, Charles
    chamber = random.randint(1,6)
    if chamber == chamber_with_bullet:
        dead = True
    else:
        print(f"BLAM: CHAMBER {chamber} IS SAFE!")
        game_rounds -= 1
        if game_rounds == 0:
            # The else block is skipped: you're alive!
            print("Congrats, pardner, you're alive!")
            break
else:
    print(f"BLAM: DEAD.\nThe bullet was in chamber {chamber_with_bullet}.")