Bitcoin Forum
July 20, 2019, 06:31:51 AM *
News: Latest Bitcoin Core release: 0.18.0 [Torrent] (New!)
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Python bug fix help  (Read 61 times)
crypture
Newbie
*
Offline Offline

Activity: 31
Merit: 0


View Profile WWW
April 03, 2019, 07:05:49 PM
 #1

I wonder if a python expert can help me. I have this .py file i'm trying to run on OSX 10.11.6 but when i try to run the file whilst in the same directory i get this error
Code:
Traceback (most recent call last):
  File "wavtotext.py", line 24, in <module>
    w = wave.open(fileName, 'r')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wave.py", line 511, in open
    return Wave_read(f)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wave.py", line 164, in __init__
    self.initfp(f)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wave.py", line 144, in initfp
    self._read_fmt_chunk(chunk)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wave.py", line 274, in _read_fmt_chunk
    raise Error, 'unknown format: %r' % (wFormatTag,)
wave.Error: unknown format: 3
 
file.py
Code:
import wave
import math
import struct

bitDepth = 8#target bitDepth
frate = 44100#target frame rate

fileName = "musicfile.wav"#file to be imported (change this)

#read file and get data
w = wave.open(fileName, 'r')
numframes = w.getnframes()

frame = w.readframes(numframes)#w.getnframes()

frameInt = map(ord, list(frame))#turn into array

#separate left and right channels and merge bytes
frameOneChannel = [0]*numframes#initialize list of one channel of wave
for i in range(numframes):
    frameOneChannel[i] = frameInt[4*i+1]*2**8+frameInt[4*i]#separate channels and store one channel in new list
    if frameOneChannel[i] > 2**15:
        frameOneChannel[i] = (frameOneChannel[i]-2**16)
    elif frameOneChannel[i] == 2**15:
        frameOneChannel[i] = 0
    else:
        frameOneChannel[i] = frameOneChannel[i]

#convert to string
audioStr = ''
for i in range(numframes):
    audioStr += str(frameOneChannel[i])
    audioStr += ","#separate elements with comma

fileName = fileName[:-3]#remove .wav extension
text_file = open(fileName+"txt", "w")
text_file.write("%s"%audioStr)
text_file.close()
Can someone help to get this working please ?
1563604311
Hero Member
*
Offline Offline

Posts: 1563604311

View Profile Personal Message (Offline)

Ignore
1563604311
Reply with quote  #2

1563604311
Report to moderator
1563604311
Hero Member
*
Offline Offline

Posts: 1563604311

View Profile Personal Message (Offline)

Ignore
1563604311
Reply with quote  #2

1563604311
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1563604311
Hero Member
*
Offline Offline

Posts: 1563604311

View Profile Personal Message (Offline)

Ignore
1563604311
Reply with quote  #2

1563604311
Report to moderator
1563604311
Hero Member
*
Offline Offline

Posts: 1563604311

View Profile Personal Message (Offline)

Ignore
1563604311
Reply with quote  #2

1563604311
Report to moderator
1563604311
Hero Member
*
Offline Offline

Posts: 1563604311

View Profile Personal Message (Offline)

Ignore
1563604311
Reply with quote  #2

1563604311
Report to moderator
Joel_Jantsen
Legendary
*
Offline Offline

Activity: 1288
Merit: 1234


Can I merit you with some Flags? 🚩


View Profile
April 03, 2019, 07:33:15 PM
 #2

Did you even google it? The very first SO answer is accurate

Quote
8

Python's wave module works with a specific type of WAV: PCM (WAVE_FORMAT_PCM: 0x0001).

In your case, you're using a WAV of type WAVE_FORMAT_GSM610 [0x0031 = hex(49)].

You can use a program like Audacity or some lib for converting codecs to change the type of the WAV file.

You can see a list of WAV types here: https://www.videolan.org/developers/vlc/doc/doxygen/html/vlc__codecs_8h.html

Python's wave module source code: https://github.com/python/cpython/blob/master/Lib/wave.py

Source : https://stackoverflow.com/questions/17297048/opening-a-wave-file-in-python-unknown-format-49-whats-going-wrong

If you need help with converting the formats or editing the WAV files, I can help.

.BitDice.               ▄▄███▄▄
           ▄▄██▀▀ ▄ ▀▀██▄▄
      ▄▄█ ▀▀  ▄▄█████▄▄  ▀▀ █▄▄
  ▄▄██▀▀     ▀▀ █████ ▀▀     ▀▀██▄▄
██▀▀ ▄▄██▀      ▀███▀      ▀██▄▄ ▀▀██
██  ████▄▄       ███       ▄▄████  ██
██  █▀▀████▄▄  ▄█████▄  ▄▄████▀▀█  ██
██  ▀     ▀▀▀███████████▀▀▀     ▀  ██
             ███████████
██  ▄     ▄▄▄███████████▄▄▄     ▄  ██
██  █▄▄████▀▀  ▀█████▀  ▀▀████▄▄█  ██
██  ████▀▀       ███       ▀▀████  ██
██▄▄ ▀▀██▄      ▄███▄      ▄██▀▀ ▄▄██
  ▀▀██▄▄     ▄▄ █████ ▄▄     ▄▄██▀▀
      ▀▀█ ▄▄  ▀▀█████▀▀  ▄▄ █▀▀
           ▀▀██▄▄ ▀ ▄▄██▀▀
               ▀▀███▀▀
        ▄▄███████▄▄
     ▄███████████████▄
    ████▀▀       ▀▀████
   ████▀           ▀████
   ████             ████
   ████ ▄▄▄▄▄▄▄▄▄▄▄ ████
▄█████████████████████████▄
██████████▀▀▀▀▀▀▀██████████
████                   ████
████                   ████
████                   ████
████                   ████
████                   ████
████▄                 ▄████
████████▄▄▄     ▄▄▄████████
  ▀▀▀█████████████████▀▀▀
        ▀▀▀█████▀▀▀
▄▄████████████████████████████████▄▄
██████████████████████████████████████
█████                            █████
█████                            █████
█████                            █████
█████                            █████
█████                     ▄▄▄▄▄▄▄▄▄▄
█████                   ▄█▀▀▀▀▀▀▀▀▀▀█▄
█████                   ██          ██
█████                   ██          ██
█████                   ██          ██
██████████████████▀▀███ ██          ██
 ████████████████▄  ▄██ ██          ██
   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ██          ██
             ██████████ ██          ██
           ▄███████████ ██████▀▀██████
          █████████████  ▀████▄▄████▀
[/]
crypture
Newbie
*
Offline Offline

Activity: 31
Merit: 0


View Profile WWW
April 15, 2019, 02:35:00 PM
Last edit: April 15, 2019, 03:10:30 PM by crypture
 #3

Did you even google it? The very first SO answer is accurate

Quote
8

Python's wave module works with a specific type of WAV: PCM (WAVE_FORMAT_PCM: 0x0001).

In your case, you're using a WAV of type WAVE_FORMAT_GSM610 [0x0031 = hex(49)].

You can use a program like Audacity or some lib for converting codecs to change the type of the WAV file.

You can see a list of WAV types here: https://www.videolan.org/developers/vlc/doc/doxygen/html/vlc__codecs_8h.html

Python's wave module source code: https://github.com/python/cpython/blob/master/Lib/wave.py

Source : https://stackoverflow.com/questions/17297048/opening-a-wave-file-in-python-unknown-format-49-whats-going-wrong

If you need help with converting the formats or editing the WAV files, I can help.

I did do a search but i did not find that. But thank you in any case.

Are you familiar with the program processing ?
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!