首页 > 编程语言 >python监听麦克风数据

python监听麦克风数据

时间:2023-03-02 14:33:48浏览次数:34  
标签:__ 麦克风 FORMAT python max CHUNK np data 监听

import pyaudio
import numpy as np
import time

CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100

def audioCheckAI(): # 麦克风检测ai
    global CHUNK,FORMAT,CHANNELS,RATE
    p = pyaudio.PyAudio()
    stream = p.open(format=FORMAT,channels=CHANNELS,rate=RATE,input=True,frames_per_buffer=CHUNK)

    while True:
        data = stream.read(CHUNK)
        audio_data = np.fromstring(data,dtype=np.short)
        max_dB = np.max(audio_data)
        if max_dB >= 60: # 非常弱智的判断,后期改进
            print('报警 ' + str(max_dB))

    
if __name__ == "__main__":
    audioCheckAI()

 

标签:__,麦克风,FORMAT,python,max,CHUNK,np,data,监听
From: https://www.cnblogs.com/chinatefl/p/17171679.html

相关文章

  • Python设置字符串颜色
    使用\033[3表示字体颜色,\033[4表示背景色。示例print("\033[31;1mhello")print("\033[32;1mhello")print("\033[33;1mhello")print("\033[34;1mhello")print("\033[3......
  • Python生成PDF:Reportlab的六种使用方式
     Reportlab是Python创建PDF文档的功能库这里是整理过的六种Reportlab使用方式,主要参考的是《ReportLabUserGuide》 一、使用文档模板DocTemplateReportlab的基础......
  • 新手:python里面while循环2——代码优化
    上一笔记里面,有大量重复的代码,这次来进行优化,如果有其他方法,请教教我,respect!点击查看代码#-*-coding:utf-8-*-#__author:AndyLiu#Date:2023/3/2menu={......
  • python存 文件报错
    withopen("regulation_news_02.json","w")asfile:file.write(json.dumps(data,indent=2,ensure_ascii=False))报错:Traceback(mostrecentcalllast):File......
  • python模块xlsxwriter使用
    1.安装pipinstallXlsxWriter2.使用#-*-coding:utf-8-*-fromioimportBytesIOimportqrcode#[email protected]('/atta......
  • python---文件操作
    1.文件操作步骤打开文件-open读---把文件的内容读到变量里-read 写---把变量的值写到文件内容里-write关闭文件-close2.读取一个文件1)打开文件file=open(要打开......
  • django 源码解读 python manage.py makemigrations
    分析命令之前,需要先了解makemigrations调用的一些类。这样对于后面分析命令时很轻松。1.MigrationRecorder类这个类在django/db/migrations/recorder.py文件中,这个类是......
  • 有趣又实用的python脚本
    1.使用Python进行速度测试这个高级脚本帮助你使用Python测试你的Internet速度。只需安装速度测试模块并运行以下代码。#pipinstallpyspeedtest#pipinstalls......
  • Python抓取数据具体流程
    之前看了一段有关爬虫的网课深有启发,于是自己也尝试着如如何过去爬虫百科“python”词条等相关页面的整个过程记录下来,方便后期其他人一起来学习。抓取策略确定目标:重要......
  • 机器学习python环境搭建
    目的:跑通下面代码相关代码fromtorchimportnnimporttorchimportjiebaimportnumpyasnpraw_text="""越努力就越幸运"""words=list(jieba.cut(raw_text))......