-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
440 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: publish github release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
releaseversion: | ||
description: 'Release version' | ||
required: true | ||
default: '0.0.1' | ||
|
||
|
||
jobs: | ||
publish-github-release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Generate changelog | ||
id: changelog | ||
uses: metcalfc/[email protected] | ||
with: | ||
myToken: ${{ secrets.GH_TOKEN }} | ||
|
||
- name: Create GitHub Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||
with: | ||
tag_name: ${{ github.event.inputs.releaseversion }} | ||
release_name: ${{ github.event.inputs.releaseversion }} | ||
body: | | ||
### Things that changed in this release | ||
${{ steps.changelog.outputs.changelog }} | ||
draft: false | ||
prerelease: ${{ contains(github.event.inputs.releaseversion, '-') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
application.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
wrapperVersion=3.3.2 | ||
distributionType=only-script | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.3.3</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>io.github.pig-mesh.ai</groupId> | ||
<artifactId>volcengine-tts-spring-boot-starter</artifactId> | ||
<version>0.0.1</version> | ||
<name>volcengine-tts-spring-boot-starter</name> | ||
<description>火山引擎的 TTS 工具类</description> | ||
<url/> | ||
<licenses> | ||
<license/> | ||
</licenses> | ||
<developers> | ||
<developer/> | ||
</developers> | ||
<scm> | ||
<connection/> | ||
<developerConnection/> | ||
<tag/> | ||
<url/> | ||
</scm> | ||
<properties> | ||
<java.version>17</java.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.dreamlu</groupId> | ||
<artifactId>mica-auto</artifactId> | ||
<version>3.1.4</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>release</id> | ||
<build> | ||
<plugins> | ||
<!-- Source --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>2.2.1</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar-no-fork</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<!-- Javadoc --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>3.3.2</version> | ||
<configuration> | ||
<show>private</show> | ||
<nohelp>true</nohelp> | ||
<charset>UTF-8</charset> | ||
<encoding>UTF-8</encoding> | ||
<docencoding>UTF-8</docencoding> | ||
<doclint>none</doclint> | ||
<detectJavaApiLink>false</detectJavaApiLink> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<!-- GPG --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-gpg-plugin</artifactId> | ||
<version>3.0.1</version> | ||
<executions> | ||
<execution> | ||
<id>sign-artifacts</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>sign</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<gpgArguments> | ||
<arg>--pinentry-mode</arg> | ||
<arg>loopback</arg> | ||
</gpgArguments> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.sonatype.central</groupId> | ||
<artifactId>central-publishing-maven-plugin</artifactId> | ||
<version>0.5.0</version> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<publishingServerId>center</publishingServerId> | ||
<autoPublish>true</autoPublish> | ||
<waitUntil>published</waitUntil> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<distributionManagement> | ||
<repository> | ||
<id>sonatype</id> | ||
<url> | ||
https://oss.sonatype.org/service/local/staging/deploy/maven2/ | ||
</url> | ||
</repository> | ||
</distributionManagement> | ||
</profile> | ||
</profiles> | ||
</project> |
39 changes: 39 additions & 0 deletions
39
src/main/java/io/github/pigmesh/ai/volcengine/tts/VolcengineTtsAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.github.pigmesh.ai.volcengine.tts; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.github.pigmesh.ai.volcengine.tts.config.TtsProperties; | ||
import io.github.pigmesh.ai.volcengine.tts.core.VolcengineTtsService; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
/** | ||
* @author lengleng | ||
* @date 2024/9/3 | ||
*/ | ||
@AutoConfiguration | ||
@EnableConfigurationProperties(TtsProperties.class) | ||
public class VolcengineTtsAutoConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public RestTemplate restTemplate() { | ||
return new RestTemplate(); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public ObjectMapper objectMapper() { | ||
return new ObjectMapper(); | ||
} | ||
|
||
@Bean | ||
public VolcengineTtsService volcengineTtsService( | ||
RestTemplate restTemplate, | ||
ObjectMapper objectMapper, | ||
TtsProperties ttsProperties) { | ||
return new VolcengineTtsService(restTemplate, objectMapper, ttsProperties); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/io/github/pigmesh/ai/volcengine/tts/config/TtsProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.github.pigmesh.ai.volcengine.tts.config; | ||
|
||
|
||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@Data | ||
@ConfigurationProperties(prefix = "tts") | ||
public class TtsProperties { | ||
|
||
private String apiUrl = "https://openspeech.bytedance.com/api/v1/tts"; | ||
private String accessToken; | ||
private String appId = "4456569928"; | ||
private String cluster = "volcano_tts"; | ||
private String uid = "388808087185088"; | ||
|
||
private String voice_type = "BV002"; | ||
private String encoding = "mp3"; | ||
private float speed_ratio = 1; | ||
private float volume_ratio = 1; | ||
private float pitch_ratio = 1; | ||
private String emotion = "happy"; | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/io/github/pigmesh/ai/volcengine/tts/core/VolcengineTtsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.github.pigmesh.ai.volcengine.tts.core; | ||
|
||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.github.pigmesh.ai.volcengine.tts.config.TtsProperties; | ||
import io.github.pigmesh.ai.volcengine.tts.model.TtsRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
/** | ||
* VolcEngine TTS 服务 | ||
* | ||
* @author lengleng | ||
* @date 2024/09/03 | ||
*/ | ||
@RequiredArgsConstructor | ||
public class VolcengineTtsService { | ||
|
||
private final RestTemplate restTemplate; | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
private final TtsProperties ttsProperties; | ||
|
||
/** | ||
* 合成语音 | ||
* | ||
* @param text 发短信 | ||
* @return {@link String } | ||
* @throws IOException io异常 | ||
*/ | ||
public String synthesizeVoice(String text) throws IOException { | ||
TtsRequest ttsRequest = new TtsRequest(text); | ||
ttsRequest.getApp().setAppid(ttsProperties.getAppId()); | ||
ttsRequest.getApp().setCluster(ttsProperties.getCluster()); | ||
ttsRequest.getApp().setToken(ttsProperties.getAccessToken()); | ||
ttsRequest.getUser().setUid(UUID.randomUUID().toString()); | ||
|
||
ttsRequest.getAudio().setEmotion(ttsProperties.getEmotion()); | ||
ttsRequest.getAudio().setEncoding(ttsProperties.getEncoding()); | ||
ttsRequest.getAudio().setPitch_ratio(ttsProperties.getPitch_ratio()); | ||
ttsRequest.getAudio().setSpeed_ratio(ttsProperties.getSpeed_ratio()); | ||
ttsRequest.getAudio().setVolume_ratio(ttsProperties.getVolume_ratio()); | ||
ttsRequest.getAudio().setVoice_type(ttsProperties.getVoice_type()); | ||
ttsRequest.getRequest().setReqid(UUID.randomUUID().toString()); | ||
String jsonRequest = objectMapper.writeValueAsString(ttsRequest); | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
headers.set(HttpHeaders.AUTHORIZATION, "Bearer;" + ttsProperties.getAccessToken()); | ||
HttpEntity<String> entity = new HttpEntity<>(jsonRequest, headers); | ||
String responseString = restTemplate.postForObject(ttsProperties.getApiUrl(), entity, String.class); | ||
Map<String, String> responseMap = objectMapper.readValue(responseString, Map.class); | ||
return responseMap.get("data"); | ||
} | ||
} |
Oops, something went wrong.