Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0952631f
authored
Oct 17, 2025
by
feitianbubu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add doubao tts usage token
parent
1be4e12c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
6 deletions
+3
-6
relay/channel/volcengine/adaptor.go
+1
-1
relay/channel/volcengine/tts.go
+2
-5
No files found.
relay/channel/volcengine/adaptor.go
View file @
0952631f
...
...
@@ -319,7 +319,7 @@ func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, request
func
(
a
*
Adaptor
)
DoResponse
(
c
*
gin
.
Context
,
resp
*
http
.
Response
,
info
*
relaycommon
.
RelayInfo
)
(
usage
any
,
err
*
types
.
NewAPIError
)
{
if
info
.
RelayMode
==
constant
.
RelayModeAudioSpeech
{
encoding
:=
mapEncoding
(
c
.
GetString
(
"response_format"
))
return
handleTTSResponse
(
c
,
resp
,
encoding
)
return
handleTTSResponse
(
c
,
resp
,
info
,
encoding
)
}
adaptor
:=
openai
.
Adaptor
{}
...
...
relay/channel/volcengine/tts.go
View file @
0952631f
...
...
@@ -119,6 +119,7 @@ func mapVoiceType(openAIVoice string) string {
return
openAIVoice
}
// [0.1,2],默认为 1,通常保留一位小数即可
func
mapSpeedRatio
(
speed
float64
)
float64
{
if
speed
==
0
{
return
1.0
...
...
@@ -133,9 +134,6 @@ func mapSpeedRatio(speed float64) float64 {
}
func
mapEncoding
(
responseFormat
string
)
string
{
if
responseFormat
==
""
{
return
"mp3"
}
if
encoding
,
ok
:=
responseFormatToEncodingMap
[
responseFormat
];
ok
{
return
encoding
}
...
...
@@ -155,7 +153,7 @@ func getContentTypeByEncoding(encoding string) string {
return
"application/octet-stream"
}
func
handleTTSResponse
(
c
*
gin
.
Context
,
resp
*
http
.
Response
,
encoding
string
)
(
usage
any
,
err
*
types
.
NewAPIError
)
{
func
handleTTSResponse
(
c
*
gin
.
Context
,
resp
*
http
.
Response
,
info
*
relaycommon
.
RelayInfo
,
encoding
string
)
(
usage
any
,
err
*
types
.
NewAPIError
)
{
body
,
readErr
:=
io
.
ReadAll
(
resp
.
Body
)
if
readErr
!=
nil
{
return
nil
,
types
.
NewErrorWithStatusCode
(
...
...
@@ -196,7 +194,6 @@ func handleTTSResponse(c *gin.Context, resp *http.Response, encoding string) (us
c
.
Header
(
"Content-Type"
,
contentType
)
c
.
Data
(
http
.
StatusOK
,
contentType
,
audioData
)
info
:=
c
.
MustGet
(
"relay_info"
)
.
(
*
relaycommon
.
RelayInfo
)
usage
=
&
dto
.
Usage
{
PromptTokens
:
info
.
PromptTokens
,
CompletionTokens
:
0
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment