Skip to content

Commit

Permalink
renew sessionId and hardcode wss
Browse files Browse the repository at this point in the history
  • Loading branch information
roffidaijoubu committed Dec 28, 2024
1 parent dfd498a commit fcebbe3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
9 changes: 9 additions & 0 deletions assets/avatar.html
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,17 @@ <h3 class="font-medium mb-2">Latest Message:</h3>
setAudioStatus('info', 'Loading audio...')
audio.src = url

// Set audio attributes for better compatibility
audio.preload = 'auto'
audio.crossOrigin = 'anonymous'
audio.type = 'audio/mpeg'

// Force reload the audio element
audio.load()

audio.play().catch(e => {
const error = `Failed to play audio: ${e.message}`
console.error('Audio play error:', e)
setAudioStatus('error', error)
setAvatarState(false)
sendAvatarFinished(url, error)
Expand Down
4 changes: 2 additions & 2 deletions assets/js/control/ConnectionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export class ConnectionManager {
return;
}

const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `${protocol}//chatsocket.oristarium.com/ws`;
// const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `wss://chatsocket.oristarium.com/ws`;

console.log('Connecting to WebSocket:', wsUrl);
this.ws = new WebSocket(wsUrl);
Expand Down
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,21 @@ func (s *Server) setupRoutes() {
return
}

// Serve the file
// Open and validate the file
file, err := os.Open(blobPath)
if err != nil {
http.Error(w, "Failed to read audio file", http.StatusInternalServerError)
return
}
defer file.Close()

// Set proper headers
w.Header().Set("Content-Type", "audio/mpeg")
w.Header().Set("Accept-Ranges", "bytes")
w.Header().Set("Cache-Control", "no-cache")
w.Header().Set("Access-Control-Allow-Origin", "*")

// Serve the file
http.ServeFile(w, r, blobPath)
})
}
Expand Down
2 changes: 1 addition & 1 deletion tts/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ const (
MaxTextLength = 200 // Maximum length of text that can be processed at once
ProviderGoogle = "google"
ProviderTikTok = "tiktok"
TikTokSessionID = "1ba7018e2f1934534b23cb878562fd85"
TikTokSessionID = "c673246e12e407380845a488af057da9"
)
20 changes: 14 additions & 6 deletions tts/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,27 @@ func (tm *TTSMiddleware) getAudioBlob(text string, voiceId string, provider stri
return "", fmt.Errorf("failed to decode base64 audio: %v", err)
}

// Create temporary file
blobFile, err := os.CreateTemp(tm.blobDir, "tts_*.mp3")
// Validate audio data
if len(audioData) < 4 {
return "", fmt.Errorf("invalid audio data: too short")
}

// Create temporary file with proper permissions
blobFile, err := os.OpenFile(
filepath.Join(tm.blobDir, fmt.Sprintf("tts_%d.mp3", time.Now().UnixNano())),
os.O_WRONLY|os.O_CREATE|os.O_TRUNC,
0644,
)
if err != nil {
return "", fmt.Errorf("failed to create temp file: %v", err)
}
defer blobFile.Close()

// Write the raw audio data and close the file
if _, err := blobFile.Write(audioData); err != nil {
blobFile.Close()
// Write the raw audio data
if _, err := io.Copy(blobFile, bytes.NewReader(audioData)); err != nil {
os.Remove(blobFile.Name())
return "", fmt.Errorf("failed to write audio data: %v", err)
}
blobFile.Close()

// Schedule cleanup after 5 minutes
tm.queueCleanup(blobFile.Name(), 5*time.Minute)
Expand Down

0 comments on commit fcebbe3

Please sign in to comment.