I am trying to make a game where you can give it a song and it checks for the note with the highest volume in intervals eg, 5 seconds or so. This way it can place a button on the screen at that time for the player to click. I'm currently trying to wrap my head around the way some of this audio analysing stuff works and keep getting this error I am unable to fix.
My code:
import pyautogui
import win32api, win32con
import threading
import time
from time import sleep
import keyboard
import random
from ast import Str
import pygame
from pygame import *
import sys
import math
import numpy
import matplotlib
import matplotlib.pyplot
import pydub
from pydub import AudioSegment
song = AudioSegment.from_mp3(r"C:\Users\William Cunningham\Desktop\Stuff\Visual Studio\Games\KeyClickGame\AlienWaifus.mp3")
SEGMENT_MS = 50
volume = [segment.dBFS for segment in song[::SEGMENT_MS]]
x_axis = numpy.arrange(len(volume)) * (SEGMENT_MS / 1000)
matplotlib.pyplot.plot(x_axis, volume)
matplotlib.pyplot.show
The error I am getting:
C:\Users\William Cunningham\AppData\Local\Programs\Python\Python310\lib\site-packages\pydub\utils.py:170: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
C:\Users\William Cunningham\AppData\Local\Programs\Python\Python310\lib\site-packages\pydub\utils.py:198: RuntimeWarning: Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work
warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)
Traceback (most recent call last):
File "c:\Users\William Cunningham\Desktop\Stuff\Visual Studio\Games\KeyClickGame\AudioStuff.py", line 33, in <module>
song = AudioSegment.from_mp3(file=r"C:\Users\William Cunningham\Desktop\Stuff\Visual Studio\Games\KeyClickGame\AlienWaifus.mp3")
File "C:\Users\William Cunningham\AppData\Local\Programs\Python\Python310\lib\site-packages\pydub\audio_segment.py", line 796, in from_mp3
return cls.from_file(file, 'mp3', parameters=parameters)
File "C:\Users\William Cunningham\AppData\Local\Programs\Python\Python310\lib\site-packages\pydub\audio_segment.py", line 728, in from_file
info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
File "C:\Users\William Cunningham\AppData\Local\Programs\Python\Python310\lib\site-packages\pydub\utils.py", line 274, in mediainfo_json
res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
File "C:\Users\William Cunningham\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\William Cunningham\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
I'm quite new to coding so I don't have any idea what this means, however I believe at the last line it seems to say it cant find my file however it is clearly there.
I have attempted to change:
song = AudioSegment.from_mp3(r"C:\Users\William Cunningham\Desktop\Stuff\Visual Studio\Games\KeyClickGame\AlienWaifus.mp3")
to:
song = AudioSegment.from_mp3(file=r"C:\Users\William Cunningham\Desktop\Stuff\Visual Studio\Games\KeyClickGame\AlienWaifus.mp3")
I have also tried it without the r in r". And furthermore tried it as only "AlienWaifus.mp3". I have also tried to do the same things with from_file instead of from_mp3. Adding to this I have attempted to do SongA = open(r"C:\Users\William Cunningham\Desktop\Stuff\Visual Studio\Games\KeyClickGame\AlienWaifus.mp3")
and then do SongB = AudioSegment.from_file(SongA)
, and also SongB = AudioSegment.from_mp3(SongA)
.
I'm not sure what I'm doing to be completely honest though I have tried everything I could think of, and eventually decided to come here. (I'm new so my formatting on the question may not be right please let me know if this is the case!)
What I Want: I want to have code that looks at an audio file (.mp3) and for each say 10 second interval in the song (the audio file is a song) it checks at what point it is loudest. In decibels. So it say returns a time, furthermore I would like to be able to get graphs for different things and even play the song but at the moment I just want to get this working. (My code at the moment is for a graph that shows volume of the .mp3 file over time but it doesn't work and I want it to work.) Note: I would prefer not to install any software and just be able to code this if possible.