测试无线电的连通性想到用蜂鸣,整理到以下案例,亲测有效。
Python
Windows OS
import winsound
duration = 1000
freq = 440
winsound.Beep(freq, duration)
Linux and Mac OS
import os
duration = 1
freq = 440
os.system('play -nq -t alsa synth {} sine {}'.format(duration, freq))
在Linux或Mac上调用蜂鸣器需要安装sox
sudo apt install sox
sudo port install sox
C++
Windows OS
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
int duration = 1000;
int freq = 440;
Beep(freq, duration);
cin.get();
return 0;
}
Linux and Mac OS
int main()
{
int duration = 1;
int freq = 440;
char command[100] = {0};
sprintf(command, "play -nq -t alsa synth %d sine %d", duration, freq);
system(command);
cin.get();
return 0;
}
执行以上案例前需要安装sox ,安装方法参见Python部分。
|