Hello Mat

 找回密码
 立即注册
查看: 5584|回复: 0

音频.wav处理

[复制链接]

1319

主题

1547

帖子

0

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22631
发表于 2017-10-23 20:45:45 | 显示全部楼层 |阅读模式
需要执行HMM的朋友,请自行安装:python_speech_features,请参考http://python-speech-features.readthedocs.org/en/latest.
使用环境:Win7-32bit-Anaconda2-4.3.1-Windows-x86.exe
  1. import numpy as np
  2. from scipy.io import wavfile
  3. import matplotlib.pyplot as plt

  4. # Read the input file
  5. sampling_freq, audio = wavfile.read('input_freq.wav')

  6. # Normalize the values
  7. audio = audio / (2.**15)

  8. # Extract length
  9. len_audio = len(audio)

  10. # Apply Fourier transform
  11. transformed_signal = np.fft.fft(audio)
  12. half_length = np.ceil((len_audio + 1) / 2.0)
  13. transformed_signal = abs(transformed_signal[0:half_length])
  14. transformed_signal /= float(len_audio)
  15. transformed_signal **= 2

  16. # Extract length of transformed signal
  17. len_ts = len(transformed_signal)

  18. # Take care of even/odd cases
  19. if len_audio % 2:
  20.     transformed_signal[1:len_ts] *= 2
  21. else:
  22.     transformed_signal[1:len_ts-1] *= 2

  23. # Extract power in dB
  24. power = 10 * np.log10(transformed_signal)

  25. # Build the time axis
  26. x_values = np.arange(0, half_length, 1) * (sampling_freq / len_audio) / 1000.0

  27. # Plot the figure
  28. plt.figure()
  29. plt.plot(x_values, power, color='black')
  30. plt.xlabel('Freq (in kHz)')
  31. plt.ylabel('Power (in dB)')
  32. plt.show()
复制代码

参考:https://github.com/PacktPublishing/Python-Machine-Learning-Cookbook






算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-10-31 18:24 , Processed in 0.225297 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表