Accessing a folder containing .wav files [closed]

2024/10/5 11:30:33

I am trying to access a folder containing 50 .wav file samples (that I will use for my Gender Voice Classification (using PCA) project), but I cant seem to be able to access the folder properly. The folder is unzipped of course.

the folder containing the file samples is named "SoundSamples", that is inside another folder named "soundFile" that is located on the desktop.

I am running the code below:

import osraw_folder = '//Desktop//soundFile//SoundSamples//'
for file in os.listdir(raw_folder):print(file)filepath = os.path.join(raw_folder, file)f = open(filepath, 'r')print(f.read())f.close()

The output I get is an error saying "no such file or directory: '//Desktop//soundFile//SoundSamples//' "

Answer

You cannot access the relative path to your Desktop folder by starting with the absolute path /Desktop/... As a regular user, your desktop folder is stored somewhere deeper -- typically, something like /Users/(yourname)/Desktop. But don't hardcode that, Python can find the home folder for you!

import os
from os.path import expanduserhome = expanduser("~")
print home
raw_folder = home+'/Desktop/soundFile/SoundSamples'
for file in os.listdir(raw_folder):print(file)

The OS function expanduser locates your home folder and returns it as a string. Then you can paste on whatever folder you are looking for -- Desktop, Documents, or any other path relative to your home.

https://en.xdnf.cn/q/119027.html

Related Q&A

What is the right Python idiom for sorting by a single criterion (field or key)? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 8…

Incorrect checking of fields in list using a for loop

I have the following code that seeks to read the file contents into a list (this bit works) and then display a message of acceptance, IF the bank details (user and corresponding number) matches. e.g. i…

Why myVar = strings.Fields(scanner.Text()) take much more time than comparable operation in python?

Consider the following code in golangnow := time.Now() sec1 := now.Unix()file, err := os.Open(file_name) if err != nil {log.Fatal(err) } defer file.Close()scanner := bufio.NewScanner(file)var parsedLin…

When reading an excel file in Python can we know which column/field is filtered

I want to capture the field or column name that is filtered in the excel file when reading through python. I saw that we can also capture only the filtered rows by using openpyxl and using hidden == Fa…

Error:__init__() missing 1 required positional argument: rec

I am new to python. I am trying to do microphone file that ought to detect, listen, record and write the .wav files. However, it is giving me an error while I am trying to run the file. It is saying:Ty…

Maya: Connect two Joint chains with Parent Constraint

So here is a snipit of an IK spine builder Ive been working on. Ive figure out how to make lists to duplicate the bound into an IK chain, what Ive got stuck on however is I want my list and for loop to…

What is the equivalent for onkeydown and onkeyup (Javascript events) in python?

There are events called onkeydown and onkeyup in Javascript. Can anyone please suggest the python equivalent of it?

Matching number string pairs

I have the following sample string:R10666: 273141 C1 + 273141 C2 + 273141 C3 + 273141 C4 + 273141 C5 - 273141 C6I want to obtain:[(273141,C1), ..., (- 273141, C6)]The numbers can be floating point numb…

Turning a text file into a tabular format [duplicate]

This question already has answers here:How do I print parameters of multiple objects in table form? [duplicate](2 answers)Line up columns of numbers (print output in table format)(7 answers)Closed 5 y…

Python: Read file with list as list

I have placed a list in a text file. I want python to read the text file and return the contents as a list. However, it is instead reading the content as a string:Text file:[a,b,c]Python:ids=[]writtenF…