Running this snippet of code:
while True:
print('recording')
myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=1, dtype=np.int16)
sd.wait() # Wait until recording is finished
write('output.wav', fs, myrecording.astype(np.int16))
sound = AudioSegment.from_file("output.wav", format="wav")
lsound = sound + 35
silence = silence.detect_nonsilent(lsound, min_silence_len=1000, silence_thresh=-15)
silence = [((start/1000),(stop/1000)) for start,stop in silence] #convert to sec
print(silence)
print(len(silence))
if len(silence) == 0:
print('silence')
else:
print('have recording')
lsound.export("loutput.wav", format='wav')
During first iteration every thing works fine
recording
[(0.0, 0.502), (1.842, 5.0)]
2
have recording
But during next iteration get:
recording
Traceback (most recent call last):
File "sttgft.py", line 43, in <module>
silence = silence.detect_nonsilent(lsound, min_silence_len=1000, silence_thresh=-15)
AttributeError: 'list' object has no attribute 'detect_nonsilent'
Attempted to delete 'silence' with del silence command but then get;
Traceback (most recent call last):
File "sttgf1.py", line 43, in <module>
silence = silence.detect_nonsilent(lsound, min_silence_len=1000, silence_thresh=-15)
NameError: name 'silence' is not defined
Don't know what to try
If you delete silence then the line of code below will throw an error as to get the final silence, it must be already there.
silence = silence.detect_nonsilent(lsound, min_silence_len=1000, silence_thresh=-15)
Now check what is the value of silence before while loop, because once it completes the first iteration silence becomes a list datatype and the same line of code mentioned above will do a list.detect_nonsilent. That is why you are getting the first error after first iteration.
Stupid mistake. Using the name 'silence' in 'silence = silence.detect_nonsilent...'
caused the error. once I changed to "silenc = silence.detect_nonsilent..." it worked perfectly.
Related
I got an error message that didn't make sense in a script that scrapes websites for Ethereum prices.
This is where the exception was raised:
# part of a loop
....
element = browser.find_element_by_css_selector(selector)
data = element.text.split('\n')
symbol, price = tuple(data[-2].split(' '))
assert symbol == 'Ξ'
total_price += float(price)
price_list.append((total_price, dict_with_data))
# in top namespace
price_list.sort() #<-- the acual line that raised an exception
This is the false traceback:
Traceback (most recent call last):
File ..., line 142, in <module>
assert symbol == 'Ξ'
TypeError: '<' not supported between instances of 'dict' and 'dict'
The error message is correct and I already fixed it, but it says the error happaned in the line assert symbol == 'Ξ' which is obviously wrong because it happened in the line price_list.sort(). Why is this traceback giving me false information?
I have made this code, to get the year from an mp3, and if i print it, it works, but when i write to text box in my webpage, it gives an error(traceback below), but not always, sometimes the error not show, so i suspect it is from the way the mp3 is tagged:
nfo_year = ''
audio_filename = 'myfile.mp3'
f = mutagen.File(audio_filename)
audio = ID3(audio_filename) # path: path to file
# Year
try:
nfo_year = audio['TDRC'].text[0]
print(nfo_year)
except:
pass
time.sleep(2)
logger_internet.info('Writing Year...')
AB_author = driver.find_element_by_name('year')
AB_author.send_keys(nfo_year)
Traceback (most recent call last):
File "D:\AB\redacted.py", line 1252, in <module>
AB_author.send_keys(nfo_year)
File "D:\AB\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 478, in send_keys
{'text': "".join(keys_to_typing(value)),
File "D:\AB\venv\lib\site-packages\selenium\webdriver\common\utils.py", line 150, in keys_to_typing
for i in range(len(val)):
TypeError: object of type 'ID3TimeStamp' has no len()
my question is: an error on the mp3 tag or am i doing something wrong?
nfo_year is a timestamp object, of type ID3TimeStamp. You have to pass strings to AB_author.send_keys. Since print worked, you can try str(nfo_year).
edited..
full traceback:
Traceback (most recent call last):
File "dscli.py", line 36, in <module>
main()
File "dscli.py", line 31, in main
instance_StreamingDownloader.download_all()
File "file.py", line 283, in download_all
time_first_frame_last_segment = self.get_time_saved_segment(crrt_segment - 1)
File "file.py", line 239, in get_time_saved_segment
return(start_time)
UnboundLocalError: local variable 'start_time' referenced before assignment
code here
It gets only first segment and then error.
How can I solve this issue?
code from github
the answer is quite simple -
the condition allows some case when start_time is not defined during script run
so as it is not defined - it fails
start_time is defined inside an if statement that's inside a for loop.
What if you don't enter the loop, or the condition isn't met? What should the function return?
start_time needs to be initialized (eg start_time = 0 / None / False) in the function body, outside any control flow clauses, so that it's always defined, and therefore you can always return it.
when condition isn't met then:
Traceback (most recent call last):
File "dscli.py", line 36, in <module>
main()
File "dscli.py", line 31, in main
instance_StreamingDownloader.download_all()
File "file.py", line 286, in download_all
lenght_ahead_buffered = time_first_frame_last_segment - time_if_streaming + random_perturbation
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'
line 280-286:
while continue_download:
time_first_frame_last_segment = self.get_time_saved_segment(crrt_segment - 1)
time_if_streaming = time.time() - init_time
random_perturbation = random.gauss(0, self.random_time)
if self.verbose > 1:
print("time in video if streaming: " + str(time_if_streaming))
Extremely confused here... trying to select all items in a QListWidget. Strangely enough I have done this before fine with this code, but this time it is barking back at me?
# Error: 'PySide.QtGui.QListWidget' object has no attribute 'setItemSelected'
# Traceback (most recent call last):
# File "<maya console>", line 2, in <module>
# ...............
# self.locListWidget.setItemSelected(item, True)
# AttributeError: 'PySide.QtGui.QListWidget' object has no attribute 'setItemSelected' #
if (sizeDimensionLocators > 0):
for loc in dimensionLocators:
self.locListWidget.addItem(loc)
for i in range(self.locListWidget.count()):
item = self.locListWidget.item(i)
self.locListWidget.setItemSelected(item, True) <---------- Issue Here
QListWidget doesn't have a setItemSelected:
https://srinikom.github.io/pyside-docs/PySide/QtGui/QListWidget.html#PySide.QtGui.QListWidget
http://doc.qt.io/archives/qt-4.8/qlistwidget.html#selectedItems
You can do this though:
item.setSelected(true)
http://doc.qt.io/qt-5/qlistwidgetitem.html#setSelected
You might also need to review the selection mode:
https://srinikom.github.io/pyside-docs/PySide/QtGui/QAbstractItemView.html#PySide.QtGui.PySide.QtGui.QAbstractItemView.setSelectionMode
I keep getting this error in my program and I have no idea how to fix it. Here's where the error comes.
def check_file():
for read in range(6):
length = len(linecache.getline('status.py', read))
f = linecache.getline('status.py', read)[0:length-1]
print (f)
if read >= 6:
print("5")
else:
file[read-1][1] = f
return file
def change_state(change_till, state): # changes tills' status
global file
data = ''
status = check_file()
status[change_till-1][1] = state
file = open('status.py', 'w')
file.write(status[0][1]+'\n'+status[1][1]+'\n'+status[2][1]+'\n'+status[3][1]+'\n'+status[4][1])
file.close()
return state
I run the code and this error comes up
Traceback (most recent call last):
File "C:\Users\rhysj\OneDrive\Documents\Rhys Morgan Jones\My Projects\Coding\Python\Months\December 2016\aldi\till.py", line 151, in <module>
start()
File "C:\Users\rhysj\OneDrive\Documents\Rhys Morgan Jones\My Projects\Coding\Python\Months\December 2016\aldi\till.py", line 144, in start
state = check_status(this_till-1)
File "C:\Users\rhysj\OneDrive\Documents\Rhys Morgan Jones\My Projects\Coding\Python\Months\December 2016\aldi\till.py", line 58, in check_status
status = check_file()
File "C:\Users\rhysj\OneDrive\Documents\Rhys Morgan Jones\My Projects\Coding\Python\Months\December 2016\aldi\till.py", line 21, in check_file
file[read-1][1] = f
TypeError: '_io.TextIOWrapper' object is not subscriptable.
Does anyone know why this happens and how to fix it?