新增讯飞语音SDK

新增机器人:开灯、开空调、语音等指令
优化每次启动程序都会重新扫描音乐库
新增晚上8点新番提醒
This commit is contained in:
yutou 2021-02-07 15:55:23 +08:00
parent a42714054f
commit 5aca836fef
12 changed files with 112 additions and 8 deletions

BIN
libmsc32.so Normal file

Binary file not shown.

BIN
libmsc64.so Normal file

Binary file not shown.

BIN
libs/Msc.jar Normal file

Binary file not shown.

BIN
libs/json-jena-1.0.jar Normal file

Binary file not shown.

BIN
msc32.dll Normal file

Binary file not shown.

BIN
msc64.dll Normal file

Binary file not shown.

14
pom.xml
View File

@ -126,6 +126,20 @@
<artifactId>ffmpeg</artifactId>
<version>0.6.2</version>
</dependency>
<dependency>
<groupId>com.iflytek</groupId>
<artifactId>msc</artifactId>
<version>4.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/Msc.jar</systemPath>
</dependency>
<dependency>
<groupId>com.iflytek</groupId>
<artifactId>json</artifactId>
<version>4.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/json-jena-1.0.jar</systemPath>
</dependency>
</dependencies>
<build>

View File

@ -9,7 +9,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ToolsApplication {
public static final String version="1.0.16.12";
public static final String version="1.0.16.13";
public static void main(String[] args) {
System.out.println("当前版本号:"+version);

View File

@ -0,0 +1,9 @@
package com.yutou.tools.other;
import com.yutou.tools.utils.AudioTools;
public class QQAudio {
public static void playText(String text){
AudioTools.playText(text);
}
}

View File

@ -20,7 +20,7 @@ public class ApplicationInit implements ApplicationRunner {
MusicTools musicTools;
@Override
public void run(ApplicationArguments args) throws Exception {
musicTools.init();//初始化音乐库
AudioTools.init();
new Timer().schedule(new TimerTask() {
@Override
public void run() {
@ -30,6 +30,7 @@ public class ApplicationInit implements ApplicationRunner {
musicTools.scanMusic();
break;
case "08:00":
case "20:00":
QQBotManager.getInstance().reportToDayBangumi();
break;
case "23:59":

View File

@ -0,0 +1,63 @@
package com.yutou.tools.utils;
import com.iflytek.cloud.speech.*;
public class AudioTools {
private static boolean init = false;
synchronized static void init() {
if (init) {
return;
}
SpeechUtility.createUtility(SpeechConstant.APPID + "=601f7f7d");
init = true;
System.out.println("讯飞语音已初始化");
}
public static void playText(String text) {
SpeechSynthesizer mss = SpeechSynthesizer.createSynthesizer();
mss.startSpeaking(text, new SynthesizerListener() {
@Override
public void onBufferProgress(int progress, int beginPos, int endPos,
String info) {
if (progress == 100) {
mss.destroy();
}
}
@Override
public void onSpeakBegin() {
}
@Override
public void onSpeakProgress(int i, int i1, int i2) {
}
@Override
public void onSpeakPaused() {
}
@Override
public void onSpeakResumed() {
}
@Override
public void onCompleted(SpeechError speechError) {
System.out.println(speechError.getErrorDesc() + " code " + speechError.getErrorCode());
}
@Override
public void onEvent(int i, int i1, int i2, int i3, Object o, Object o1) {
}
});
}
public static void main(String[] args) {
init();
playText("小爱同学,开灯");
}
}

View File

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yutou.tools.ToolsApplication;
import com.yutou.tools.bangumi.BangumiTools;
import com.yutou.tools.interfaces.DownloadInterface;
import com.yutou.tools.other.QQAudio;
import com.yutou.tools.other.QQSetu;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.BotFactory;
@ -19,6 +20,7 @@ import java.io.IOException;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Consumer;
import java.util.regex.Matcher;
@ -37,21 +39,23 @@ public class QQBotManager {
private final static String QQ_BANGUMI_TODAY = "!今日动画";
private final static String QQ_BANGUMI_LIST = "!新番";
private final static String QQ_BANGUMI_SUB = "!查动画";
private final static String QQ_AUDIO = "!语音";
private final static String QQ_AUDIO_OPEN_LAMP = "!开灯";
private final static String QQ_AUDIO_OPEN_AIR = "!开空调";
}
private static QQBotManager botManager = null;
private Bot bot;
private static final long qqGroup = 891655174L;
private boolean isLogin = false;
private static boolean isInit=false;
private static boolean isInit = false;
private QQBotManager() {
Object isRun = ConfigTools.load(ConfigTools.CONFIG, "qq_bot");
if (isRun != null && (boolean) isRun) {
isLogin = true;
isInit=true;
isInit = true;
init();
}
}
@ -101,7 +105,7 @@ public class QQBotManager {
}
public static QQBotManager getInstance() {
if (botManager == null&&!isInit) {
if (botManager == null && !isInit) {
botManager = new QQBotManager();
}
return botManager;
@ -147,8 +151,9 @@ public class QQBotManager {
}
return getNotLoginQQ();
}
public void sendMessage(Long group,MessageChainBuilder builder) {
if(bot!=null){
public void sendMessage(Long group, MessageChainBuilder builder) {
if (bot != null) {
Objects.requireNonNull(bot.getGroup(group)).sendMessage(builder.asMessageChain());
}
}
@ -221,6 +226,15 @@ public class QQBotManager {
switch (msg) {
case QQCommands.QQ_OPEN_PC:
RedisTools.Consumer.system("openPC", null);
String time = new SimpleDateFormat("HH").format(new Date());
if (Integer.parseInt(time) < 18) {
break;
}
case QQCommands.QQ_AUDIO_OPEN_LAMP:
QQAudio.playText("小爱同学,开灯");
break;
case QQCommands.QQ_AUDIO_OPEN_AIR:
QQAudio.playText("小爱同学,开空调");
break;
case QQCommands.QQ_UPDATE_IP:
RedisTools.Consumer.system("updateIP", null);
@ -238,6 +252,7 @@ public class QQBotManager {
getInstance().sendMessage("获取中...");
getInstance().sendMessage(BangumiTools.reportBangumiList());
break;
case QQCommands.QQ_HELP:
StringBuilder builder = new StringBuilder();
for (Field field : QQCommands.class.getDeclaredFields()) {
@ -270,6 +285,8 @@ public class QQBotManager {
}
}
sendImagesMsg(imgs, info);
} else if (msg.startsWith(QQCommands.QQ_AUDIO)) {
QQAudio.playText(msg.replace(QQCommands.QQ_AUDIO, ""));
}
}
}