怎么用Java实现语音报时功能啊
我的音频文件都有了,就是不知道怎么随时监控系统时间,从而达到整点报时或半点报时的功能!那位大侠帮帮忙吧!...
我的音频文件都有了,就是不知道怎么随时监控系统时间,从而达到整点报时或半点报时的功能!那位大侠帮帮忙吧!
展开
1个回答
展开全部
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
public class PlayMusic extends Thread {
// 这里即使我换成完整的文件路径也不行.
private static String FileName = "C:\\WINDOWS\\Media\\onestop.mid";
private SimpleDateFormat format = new SimpleDateFormat(
"yyyy/MM/dd hh:mm:ss");
private Sequence seq = null;
public void run() {
while (true) {
try {
Thread.sleep(500);
if (isTimeToPlay())
LoadAndPlay();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public PlayMusic() {
}
public void LoadAndPlay() {
try {
this.seq = MidiSystem.getSequence(new File(FileName));
Sequencer localSequencer = MidiSystem.getSequencer();
localSequencer.open();
localSequencer.setSequence(seq);
localSequencer.start();
} catch (Exception localException) {
localException.printStackTrace();
}
}
private boolean isTimeToPlay() {
return format.format(new Date()).endsWith("00:00"); //整点报时
//return format.format(new Date()).endsWith("30:00"); //半小时报时
}
public static void main(String[] paramArrayOfString) {
PlayMusic timeClock = new PlayMusic();
timeClock.start();
}
}
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
public class PlayMusic extends Thread {
// 这里即使我换成完整的文件路径也不行.
private static String FileName = "C:\\WINDOWS\\Media\\onestop.mid";
private SimpleDateFormat format = new SimpleDateFormat(
"yyyy/MM/dd hh:mm:ss");
private Sequence seq = null;
public void run() {
while (true) {
try {
Thread.sleep(500);
if (isTimeToPlay())
LoadAndPlay();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public PlayMusic() {
}
public void LoadAndPlay() {
try {
this.seq = MidiSystem.getSequence(new File(FileName));
Sequencer localSequencer = MidiSystem.getSequencer();
localSequencer.open();
localSequencer.setSequence(seq);
localSequencer.start();
} catch (Exception localException) {
localException.printStackTrace();
}
}
private boolean isTimeToPlay() {
return format.format(new Date()).endsWith("00:00"); //整点报时
//return format.format(new Date()).endsWith("30:00"); //半小时报时
}
public static void main(String[] paramArrayOfString) {
PlayMusic timeClock = new PlayMusic();
timeClock.start();
}
}
中智卫安
2024-11-20 广告
2024-11-20 广告
语音交互数字人,作为深圳中智卫安的前沿技术成果,拥有高度智能化的语音理解与合成能力,能够流畅自然地与用户进行对话交流。无论是信息咨询、任务指令还是情感互动,它都能迅速响应,以人性化的方式提供精准服务。通过先进的人工智能算法,不断优化对话体验...
点击进入详情页
本回答由中智卫安提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询