Rechercher dans ce blog

Friday, April 7, 2023

3 Interesting Sound Processing Techniques Using JES - MUO - MakeUseOf

JES is a program that lets you modify images, sounds, and videos programmatically. JES has many built-in functions and debugging tools to help you learn the Jython language.

When importing a file using JES, you can examine its sound waves visually, using a separate window. You can also manipulate the amplitude values of these sound waves at specific points. This can help you edit the sound file to achieve different effects.

How to Change the Volume of a Sound Clip

When you render an image in JES, you can access the individual pixels that it contains. You can achieve certain image processing techniques by editing the red, green, and blue color values for each pixel.

Similarly, a sound file contains many individual "samples" which are small pieces of sound data. You can edit an imported sound by changing the amplitude value at each sample.

The code used in this project is available in this GitHub repo under the MIT license.

  1. Open the JES application on your computer.
  2. Create a new function called changeVolume(), which takes in the volume you want to change to as an input:
     def changeVolume(vol):  
  3. Inside the function, open a prompt to ask the user to select a valid sound file. Although JES is not compatible with mp3 files, you can still import WAV files. Add some validation to make sure the file is compatible:
     file = pickAFile() 
    if file != None and file.endswith(".wav"):
      # Code for valid file
    else:
      print("Invalid file selected. Please choose a valid WAV file.")

  4. If the selected file is valid, create a sound object from it:
     sound = makeSound(file) 
  5. Loop through each sample of the sound:
     for i in range(0, getLength(sound)): 
  6. Check if the user passed up into the function to turn the volume up louder. If so, get the sample value at that index using the built-in getSampleValueAt() function. Increase the volume by doubling the amplitude, and use setSampleValueAt() to set the new value:
     if vol == 'up':
      sampleVal = getSampleValueAt(sound, i)
      setSampleValueAt(sound, i, sampleVal * 2)
  7. Check if the user passed down into the function to make the volume softer. If so, get the sample value at that index, and divide it by 2 instead, to reduce the amplitude:
     if vol == 'down':
      sampleVal = getSampleValueAt(sound, i)
      setSampleValueAt(sound, i, sampleVal / 2)
  8. Use the explore() function to open the explorer window for the sound:
     explore(sound) 
  9. Click on the Load Program button, located between the programming area and the command line. Save the file if prompted:
    JES software with save prompt open
  10. Run the changeVolume() function on the command line, passing "up" as an argument to the function:
     changeVolume("up") 
  11. Using the file explorer window, navigate to a valid sound file:
    JES software with file explorer
  12. Click on the Play Entire Sound button using the new window:
    JES Soundwaves window with wave
  13. In the command line, run the changeVolume() again with the value "down" as an argument, and select a file:
     changeVolume("down") 
  14. In the explorer window, you will see that the sound waves are smaller. Click on the Play Entire Sound button using the new window:
    JES Soundwaves that are lower volume

How to Reverse a Sound Clip

You can reverse a sound by creating a new empty sound and copying each sample of the original sound into the new sound in reverse order.

  1. In a new function, prompt the user to select a WAV file, and check that the file is valid:
     def reverseSound():
      file = pickAFile()
      if file != None and file.endswith(".wav"):
        # Code for valid file
      else:
        print("Invalid file selected. Please choose a valid WAV file.")

  2. Create a new sound object from the selected file:
     sound = makeSound(file)  
  3. Use the built-in makeEmptySound() function to create a new empty sound object. This will consist of the same number of samples as the original sound. The amplitude value for each sample will be 0:
     newReversedSound = makeEmptySound(getLength(sound)) 
  4. Loop through each sample of the new empty sound object:
     for i in range(0, getLength(newReversedSound)): 
  5. For each sample at that point, get the sample at the opposite end of the sound. For example, if the sample length is 100, and the current index is 0, this will get the sample value at index 99. Similarly, if the current index is 3, this will get the sample value at index 96:
     sampleVal = getSampleValueAt(sound, getLength(sound) - 1 - i) 
  6. Copy the sample value from the other end of the sound to the current index of the new sound:
     setSampleValueAt(newReversedSound, i, sampleVal) 
  7. Explore the new reversed sound. You can also explore the original sound for comparison purposes:
     explore(sound)
    explore(newReversedSound)
  8. Click on the Load Program button, located between the programming area and the command line. Save the file if prompted.
  9. Run the function using the command line:
     reverseSound() 
  10. View the original sound and the reversed sound using the explorer windows. Click on the Play Entire Sound button to hear the differences:
    Two windows with two soundwaves in JES

How to Join Two Sound Clips Together

To join two sound clips together, you can ask the user to select two separate WAV files. Copy each sample of both sounds onto the new sound object.

  1. Create a new function called joinSounds():
     def joinSounds(): 
  2. Use the pickAFile() function to prompt the user to select the first file. If it is invalid, print an error message:
     file1 = pickAFile()
    if file1 == None or not file1.endswith(".wav"):
      print("Invalid file selected. Please choose a valid WAV file.")

  3. Use the pickAFile() function again to ask the user for a second valid sound file:
     file2 = pickAFile() 
    if file2 == None or not file2.endswith(".wav"):
      print("Invalid file selected. Please choose a valid WAV file.")

  4. Create two sound objects from the two selected sound files:
     sound1 = makeSound(file1) 
    sound2 = makeSound(file2)
  5. Add the lengths of the two sounds together to calculate the length of the new joined sound. Create a new empty sound object using the length:
     newSoundLength = getLength(sound1) + getLength(sound2)
    joinedSound = makeEmptySound(newSoundLength)
  6. Loop through each sample of the first sound. Copy the sample value at each index onto the new sound:
     for i in range(0, getLength(sound1)):
      sampleVal = getSampleValueAt(sound1, i)
      setSampleValueAt(joinedSound, i, sampleVal)
  7. Loop through each sample of the second sound. Copy the sample value at each index onto the new sound, after the first sound:
     for i in range(0, getLength(sound2)):
      sampleVal = getSampleValueAt(sound2, i)
      endOfFirstSound = getLength(sound1) - 1
      setSampleValueAt(joinedSound, endOfFirstSound + i, sampleVal)
  8. Explore the sound using the explore() function:
     explore(joinedSound) 
  9. Click on the Load Program button, located between the programming area and the command line. Save the file if prompted.
  10. Run the function using the command line:
     joinSounds() 
  11. View the joined sound using the new window, and click on the Play Entire Sound button to hear the sound:
    Longer soundwave with joined sounds

Importing and Editing Sound Files Using JES

Now you understand how to import sound files and edit them using JES. There are so many other built-in functions that JES has to offer, that will allow you to do even more advanced sound editing.

You can learn more about the other functions available using the JES help window.

Adblock test (Why?)



"sound" - Google News
April 08, 2023 at 03:01AM
https://ift.tt/JW4lYtf

3 Interesting Sound Processing Techniques Using JES - MUO - MakeUseOf
"sound" - Google News
https://ift.tt/pKARmgD
Shoes Man Tutorial
Pos News Update
Meme Update
Korean Entertainment News
Japan News Update

No comments:

Post a Comment

Search

Featured Post

Mysterious noise irking Tampa residents may be fish mating loudly: 'Pretty uncommon phenomenon' - New York Post

Residents of Tampa, Florida have reported hearing strange noises coming from the bay for years, and now scientists believe it may be fish ...

Postingan Populer