python邮件处理模块envelopes

evelopes是Python处理邮件的一个模块,是对 email and smtplib两个模块的封装,很实用,如同用代码写邮件一样,不需要处理底层的实现

在这里下载

https://github.com/tomekwojcik/envelopes

使用也很简单,这里有个小例子:

from envelopes import Envelope, GMailSMTP

envelope = Envelope(
    from_addr=(u'from@example.com', u'From Example'),
    to_addr=(u'to@example.com', u'To Example'),
    subject=u'Envelopes demo',
    text_body=u"I'm a helicopter!"
)
envelope.add_attachment('/Users/bilbo/Pictures/helicopter.jpg')

# Send the envelope using an ad-hoc connection...
envelope.send('smtp.googlemail.com', login='from@example.com',
              password='password', tls=True)

# Or send the envelope using a shared GMail connection...
gmail = GMailSMTP('from@example.com', 'password')
gmail.send(envelope)

以下是这个类的详细API:

class envelopes.envelope.Envelope(to_addr=None, from_addr=None, subject=None, html_body=None, text_body=None, cc_addr=None, bcc_addr=None, headers=None, charset='utf-8')
The Envelope class.

Address formats

The following formats are supported for e-mail addresses:

"user@server.com" - just the e-mail address part as a string,
"Some User <user@server.com>" - name and e-mail address parts as a string,
("user@server.com", "Some User") - e-mail address and name parts as a tuple.
Whenever you come to manipulate addresses feel free to use any (or all) of the formats above.

Parameters:	
to_addr – To address or list of To addresses
from_addr – From address
subject – message subject
html_body – optional HTML part of the message
text_body – optional plain text part of the message
cc_addr – optional single CC address or list of CC addresses
bcc_addr – optional single BCC address or list of BCC addresses
headers – optional dictionary of headers
charset – message charset
add_attachment(file_path, mimetype=None)
Attaches a file located at file_path to the envelope. If mimetype is not specified an attempt to guess it is made. If nothing is guessed then application/octet-stream is used.

add_bcc_addr(bcc_addr)
Adds a BCC address.

add_cc_addr(cc_addr)
Adds a CC address.

add_header(key, value)
Adds a custom header.

add_to_addr(to_addr)
Adds a To address.

bcc_addr
List of BCC addresses.

cc_addr
List of CC addresses.

charset
Message charset.

clear_bcc_addr()
Clears list of BCC addresses.

clear_cc_addr()
Clears list of CC addresses.

clear_headers()
Clears custom headers.

clear_to_addr()¶
Clears list of To addresses.

headers
Dictionary of custom headers.

send(*args, **kwargs)
Sends the envelope using a freshly created SMTP connection. args and kwargs are passed directly to envelopes.conn.SMTP constructor.

Returns a tuple of SMTP object and whatever its send method returns.

to_addr
List of To addresses.

to_mime_message()
Returns the envelope as email.mime.multipart.MIMEMultipart.


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用python中的scipy库来求取语音信号的频谱包络。具体步骤如下: 1. 读取语音信号,可以使用Python中的wave库或者pydub库。 2. 对语音信号进行预处理,比如进行预加重、分帧、加窗等操作,可以使用Python中的librosa库。 3. 对每一帧信号进行傅里叶变换,得到频谱,可以使用Python中的numpy库或者scipy库中的fft函数。 4. 对每一帧频谱进行平滑处理,得到频谱包络,可以使用Python中的savgol_filter函数或者medfilt函数。 5. 可以将每一帧的频谱包络拼接起来,得到整个语音信号的频谱包络。 下面是一个示例代码: ```python import numpy as np from scipy import signal import matplotlib.pyplot as plt import librosa # 读取语音信号 y, sr = librosa.load('speech.wav', sr=None) # 预处理 pre_emphasis = 0.97 y_pre = signal.lfilter([1, -pre_emphasis], [1], y) frame_size = int(sr * 0.025) frame_stride = int(sr * 0.01) frames = librosa.util.frame(y_pre, frame_length=frame_size, hop_length=frame_stride) frames *= np.hamming(frame_size)[:, np.newaxis] # 计算每一帧的频谱包络 envelopes = [] for i in range(frames.shape[1]): frame = frames[:, i] # 傅里叶变换 spectrum = np.abs(np.fft.fft(frame))[:frame_size // 2] # 平滑处理 envelope = signal.savgol_filter(spectrum, 11, 3) envelopes.append(envelope) # 拼接得到整个语音信号的频谱包络 envelope = np.concatenate(envelopes) # 绘制频谱包络 plt.plot(envelope) plt.xlabel('Frequency') plt.ylabel('Envelope') plt.show() ``` 其中,示例代码使用了预加重和汉明窗加窗,使用了savgol_filter函数进行平滑处理。你也可以根据自己的需求进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值