I am trying to write a small program to find all audio files in a specific folder (and subsequent subfolders), then check if that audio file already has a .vtt or an .srt file associated with it, and if not, it should create a list of said audio files. This list is then passed to a program to create transcriptions. Here is my code so far:
import pathlib
import posixpath
# Search for all audio files, recursively
extentions = [".ogg", ".wav", ".mp3"]
folder_path = "/tmp/audiofiles/"
files = [f for f in pathlib.Path(folder_path).rglob('*') if f.suffix in extentions]
for x in files:
abs_name = posixpath.abspath(x)
print(abs_name)
filename_without_ext = abs_name.with_suffix('')
print(filename_without_ext)
The abs_name comes back as /tmp/audiofiles/2/2.ogg. So I am trying to test if /tmp/audiofiles/2/2.vtt or /tmp/audiofiles/2/2.srt exists, and if not, add /tmp/audiofiles/2/2.ogg to a the list.
I have looked at this link, especially the answer by JS, but I get the following error:
Traceback (most recent call last):
File "./get_file_list.py", line 15, in <module>
filename_without_ext = abs_name.with_suffix('')
AttributeError: 'str' object has no attribute 'with_suffix'
What am I missing here?
For beginners like me, who may need something like this in future, this is how I solved this part of my problem.