Skip to content

Commit

Permalink
听歌识曲完善
Browse files Browse the repository at this point in the history
  • Loading branch information
cph committed Oct 9, 2024
1 parent e401f43 commit a7420f5
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
Expand Down Expand Up @@ -101,6 +102,7 @@ public Object like(@RequestBody Music song) {
}

@PostMapping("/api/uploadAudio")
@RecognizeAddress
public Object recongnizeMusic(@RequestParam("audio") MultipartFile file) {
if (file.isEmpty()) {
return "{\"error\": \"请选择一个文件上传\"}";
Expand All @@ -116,7 +118,9 @@ public Object recongnizeMusic(@RequestParam("audio") MultipartFile file) {
// 保存文件
File destFile = new File(dir.getAbsolutePath() + File.separator + fileName);
file.transferTo(destFile);
return acrCloudUtil.recongizeByFile(dir.getAbsolutePath() + File.separator + fileName);
Map<String, String> resultMap = acrCloudUtil.recongizeByFile(dir.getAbsolutePath() + File.separator + fileName);
musicMapper.insert(new Music().setArtist(resultMap.get("artist")).setTitle(resultMap.get("title")));
return resultMap;
// return MusicRecUtil.recongnizeFile(dir.getAbsolutePath() + File.separator + fileName);

} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Date;

@Data
@Accessors(chain =true)
public class Music {

@TableId(type = IdType.AUTO, value = "id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public Map<String, String> recongizeByFile(String filename) {
HashMap<String, String> resultMap = new HashMap<>();
String result = re.recognizeByFile(filename, 1);
// 使用示例结果进行解析
// String result = "{\"status\":{\"msg\":\"Success\",\"version\":\"1.0\",\"code\":0},\"metadata\":{\"timestamp_utc\":\"2024-10-08 12:08:34\",\"music\":[{\"lan\":\"国语\",\"duration_ms\":200000,\"external_ids\":{},\"db_begin_time_offset_ms\":4080,\"artists\":[{\"name\":\"周杰伦\"}],\"db_end_time_offset_ms\":14600,\"sample_begin_time_offset_ms\":0,\"sample_end_time_offset_ms\":10520,\"play_offset_ms\":15540,\"result_from\":3,\"title\":\"前世情人\",\"label\":\"JVR\",\"score\":100,\"acrid\":\"e3c887cf408db8991a68a843f1afd5a0\",\"language\":\"zh\",\"external_metadata\":{},\"release_date\":\"2016-06-24\",\"album\":{\"name\":\"周杰伦的床边故事\"}},{\"duration_ms\":200460,\"external_ids\":{},\"db_begin_time_offset_ms\":4060,\"artists\":[{\"name\":\"周杰伦\"}],\"label\":\"杰威尔音乐有限公司\",\"db_end_time_offset_ms\":14500,\"sample_begin_time_offset_ms\":0,\"sample_end_time_offset_ms\":10440,\"play_offset_ms\":15520,\"result_from\":3,\"title\":\"前世情人\",\"score\":100,\"language\":\"zh\",\"acrid\":\"0eb1c19384ec445e15c6cb3c11c706ba\",\"release_date\":\"2016-06-24\",\"external_metadata\":{},\"album\":{\"name\":\"周杰伦的床边故事\"}}]},\"result_type\":0,\"cost_time\":0.029999971389771}";
System.out.println(result);

try {
Expand Down
12 changes: 6 additions & 6 deletions musicBackend/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper-locations: classpath:mybatis/*.xml

file:
upload:
path: /root/nginx/share/nginx/media/
url: https://app102.acapp.acwing.com.cn/media/
#
#file:
# upload:
# path: D://audio//
# path: /root/nginx/share/nginx/media/
# url: https://app102.acapp.acwing.com.cn/media/
file:
upload:
path: D://audio//
url: https://app102.acapp.acwing.com.cn/media/

logging:
level:
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.7.7",
"lamejs": "^1.2.1",
"react": "^18.3.1",
"react-audio-player": "^0.17.0",
"react-dom": "^18.3.1",
Expand Down
19 changes: 19 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,22 @@ html, body {
width: 150px;
height: 150px;
}

@keyframes breathe {
0% {
transform: scale(1);
opacity: 0.8;
}
50% {
transform: scale(1.05);
opacity: 1;
}
100% {
transform: scale(1);
opacity: 0.8;
}
}

.breathing-image {
animation: breathe 2s ease-in-out infinite;
}
Loading

0 comments on commit a7420f5

Please sign in to comment.