小编sta*_*345的帖子

在Python中使用LPC估计共振峰

我是信号处理的新手(对此事,还有numpy,scipy和matlab)。我正在尝试通过修改以下matlab代码来估计LPC中的元音共振峰:

http://www.mathworks.com/help/signal/ug/formant-estimation-with-lpc-coefficients.html

到目前为止,这是我的代码:

#!/usr/bin/env python
import sys
import numpy
import wave
import math
from scipy.signal import lfilter, hamming
from scikits.talkbox import lpc

"""
Estimate formants using LPC.
"""

def get_formants(file_path):

    # Read from file.
    spf = wave.open(file_path, 'r') # http://www.linguistics.ucla.edu/people/hayes/103/Charts/VChart/ae.wav

    # Get file as numpy array.
    x = spf.readframes(-1)
    x = numpy.fromstring(x, 'Int16')

    # Get Hamming window.
    N = len(x)
    w = numpy.hamming(N)

    # Apply window and high pass filter.
    x1 = x * w
    x1 = lfilter([1., -0.63], 1, …
Run Code Online (Sandbox Code Playgroud)

python matlab signal-processing numpy scipy

8
推荐指数
1
解决办法
7934
查看次数

Python Zipfile - 无效参数Errno 22

我有一个.zip文件,想知道其中的文件名.这是代码:

zip_path = glob.glob(path + '/*.zip')[0] 
file = open(zip_path, 'r') # opens without error
if zipfile.is_zipfile(file):
    print str(file) # prints to console
my_zipfile = zipfile.ZipFile(zip_path) # throws IOError
Run Code Online (Sandbox Code Playgroud)

这是追溯:

<open file u'/Users/me/Documents/project/uploads/assets/peter/offline_message/offline_imgs.zip', mode 'r' at 0x107b2a150>
Traceback (most recent call last):
  File "/Users/me/Documents/project/admin_dev/proj_name/views.py", line 1680, in get_dps_app_builder_assets
    link_to_assets_zip = zip_dps_app_builder_assets(server_url, app_slug, button_slugs)
  File "/Users/me/Documents/project/admin_dev/proj_name/views.py", line 1724, in zip_dps_app_builder_assets
    my_zipfile = zipfile.ZipFile(zip_path)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 712, in __init__
    self._GetContents()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 746, in _GetContents
    self._RealGetContents()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 779, in …
Run Code Online (Sandbox Code Playgroud)

python zipfile

6
推荐指数
1
解决办法
1691
查看次数

Django model.save()没有写入数据库

我是Django的新手,只是尝试使用ModelForms提交表单来创建一个新事件并将其保存到数据库中.

我试图将行插入三个表:Location,Event(具有location_id FK)和EventSchedule(作为event_id FK).

这是保存表单的方法.调用它时,不会返回任何错误,但新行不会插入到数据库中:

addNewEvent()(在views.py中)

def addNewEvent(self, event_form, location_form, event_sched_form, latitude, longitude):

    new_event = event_form.save(commit=False)
    new_location = location_form.save(commit=False)
    new_event_sched = event_sched_form.save(commit=False)
    # set any necessary values and save forms
    new_location.latitude = latitude
    new_location.longitude = longitude
    new_location.save()
    new_event.flagged = False
    new_event.location = new_location
    new_event.save()
    new_event_sched.event = new_event
    new_event_sched.save()
Run Code Online (Sandbox Code Playgroud)

models.py

class Location(models.Model):
    name = models.CharField(max_length=200)
    #address = models.CharField(max_length=200)
    city = models.CharField(max_length=200)
    state_code = models.CharField(max_length=100)
    zip = models.CharField(max_length=100, blank=True)
    country = models.CharField(max_length=100)
    latitude = models.DecimalField(max_digits=9, decimal_places=6)
    longitude = models.DecimalField(max_digits=9, decimal_places=6)
    class …
Run Code Online (Sandbox Code Playgroud)

database django save django-forms

2
推荐指数
1
解决办法
1万
查看次数