1
- import getAudioDuration from '../../audioDuration' ;
2
- import { generateCleanSrt } from '../../cleanSrt' ;
3
1
import { query } from '../../dbClient' ;
4
- import { secondsToSrtTime , srtTimeToSeconds } from '../../transcribeAudio' ;
5
- import { transcribeAudio } from '../../transcribeAudio' ;
6
- import { generateFillerContext } from '../../fillerContext' ;
7
- import { writeFile } from 'fs/promises' ;
8
2
import path from 'path' ;
9
3
import ffmpeg from 'fluent-ffmpeg' ;
10
4
import fs from 'fs' ;
11
5
12
6
const RVC_SERVICE_URL = process . env . RVC_SERVICE_URL || 'http://127.0.0.1:5555' ;
13
7
14
8
function adjustPath ( filePath : string ) : string {
9
+ if ( ! filePath ) {
10
+ console . error (
11
+ 'Error: filePath is undefined or null in adjustPath function'
12
+ ) ;
13
+ return '' ;
14
+ }
15
+
15
16
if ( filePath . startsWith ( '/app/shared_data/' ) ) {
16
17
return filePath . replace ( '/app/shared_data/' , '/app/brainrot/shared_data/' ) ;
17
18
} else if ( filePath . startsWith ( 'shared_data/' ) ) {
@@ -43,16 +44,35 @@ export default async function generateRap({
43
44
) ;
44
45
}
45
46
46
- const { instrumentalPath, vocalPath } = await fetch (
47
- `${ RVC_SERVICE_URL } /audio-separator` ,
48
- {
49
- method : 'POST' ,
50
- headers : {
51
- 'Content-Type' : 'application/json' ,
52
- } ,
53
- body : JSON . stringify ( { url : audioUrl } ) ,
54
- }
55
- ) . then ( ( res ) => res . json ( ) ) ;
47
+ const response = await fetch ( `${ RVC_SERVICE_URL } /audio-separator` , {
48
+ method : 'POST' ,
49
+ headers : {
50
+ 'Content-Type' : 'application/json' ,
51
+ } ,
52
+ body : JSON . stringify ( { url : audioUrl } ) ,
53
+ } ) ;
54
+
55
+ if ( ! response . ok ) {
56
+ const errorData = await response . json ( ) . catch ( ( ) => ( { } ) ) ;
57
+ console . error ( 'Audio separator API error:' , errorData ) ;
58
+ throw new Error (
59
+ `Audio separator API returned status ${ response . status } : ${
60
+ errorData . error || 'Unknown error'
61
+ } `
62
+ ) ;
63
+ }
64
+
65
+ const separatorData = await response . json ( ) ;
66
+
67
+ if ( ! separatorData . instrumentalPath || ! separatorData . vocalPath ) {
68
+ console . error (
69
+ 'Audio separator API returned incomplete data:' ,
70
+ separatorData
71
+ ) ;
72
+ throw new Error ( 'Audio separator API did not return required paths' ) ;
73
+ }
74
+
75
+ const { instrumentalPath, vocalPath } = separatorData ;
56
76
57
77
const adjustedInstrumentalPath = adjustPath ( instrumentalPath ) ;
58
78
const adjustedVocalPath = adjustPath ( vocalPath ) ;
@@ -70,7 +90,7 @@ export default async function generateRap({
70
90
) ;
71
91
}
72
92
73
- const { finalAudioPath } = await fetch ( `${ RVC_SERVICE_URL } /rvc` , {
93
+ const rvcResponse = await fetch ( `${ RVC_SERVICE_URL } /rvc` , {
74
94
method : 'POST' ,
75
95
body : JSON . stringify ( {
76
96
instrumentalPath,
@@ -80,7 +100,26 @@ export default async function generateRap({
80
100
headers : {
81
101
'Content-Type' : 'application/json' ,
82
102
} ,
83
- } ) . then ( ( res ) => res . json ( ) ) ;
103
+ } ) ;
104
+
105
+ if ( ! rvcResponse . ok ) {
106
+ const errorData = await rvcResponse . json ( ) . catch ( ( ) => ( { } ) ) ;
107
+ console . error ( 'RVC API error:' , errorData ) ;
108
+ throw new Error (
109
+ `RVC API returned status ${ rvcResponse . status } : ${
110
+ errorData . error || 'Unknown error'
111
+ } `
112
+ ) ;
113
+ }
114
+
115
+ const rvcData = await rvcResponse . json ( ) ;
116
+
117
+ if ( ! rvcData . finalAudioPath ) {
118
+ console . error ( 'RVC API returned incomplete data:' , rvcData ) ;
119
+ throw new Error ( 'RVC API did not return required finalAudioPath' ) ;
120
+ }
121
+
122
+ const { finalAudioPath } = rvcData ;
84
123
85
124
// Adjust the final audio path for the brainrot container
86
125
const adjustedFinalAudioPath = adjustPath ( finalAudioPath ) ;
0 commit comments