diff --git a/apple/OmnivoreKit/Sources/Services/AudioSession/AudioSession.swift b/apple/OmnivoreKit/Sources/Services/AudioSession/AudioSession.swift index 6300379cd..bc86572b0 100644 --- a/apple/OmnivoreKit/Sources/Services/AudioSession/AudioSession.swift +++ b/apple/OmnivoreKit/Sources/Services/AudioSession/AudioSession.swift @@ -25,6 +25,11 @@ public enum PlayerScrubState { case scrubEnded(TimeInterval) } +enum DownloadPriority: String { + case low = "low" + case high = "high" +} + // Our observable object class public class AudioSession: NSObject, ObservableObject, AVAudioPlayerDelegate { @Published public var state: AudioSessionState = .stopped @@ -77,7 +82,7 @@ public class AudioSession: NSObject, ObservableObject, AVAudioPlayerDelegate { } // Attempt to fetch the file if not downloaded already - let result = try? await downloadAudioFile(pageId: pageId) + let result = try? await downloadAudioFile(pageId: pageId, priority: .low) if result == nil { print("audio file had error downloading: ", pageId) pendingList.append(pageId) @@ -168,7 +173,7 @@ public class AudioSession: NSObject, ObservableObject, AVAudioPlayerDelegate { let pageId = item!.unwrappedID downloadTask = Task { - let result = try? await downloadAudioFile(pageId: pageId) + let result = try? await downloadAudioFile(pageId: pageId, priority: .high) if Task.isCancelled { return } if result == nil { @@ -347,14 +352,14 @@ public class AudioSession: NSObject, ObservableObject, AVAudioPlayerDelegate { } } - func downloadAudioFile(pageId: String) async throws -> (pending: Bool, url: URL?) { + func downloadAudioFile(pageId: String, priority: DownloadPriority) async throws -> (pending: Bool, url: URL?) { let audioUrl = pathForAudioFile(pageId: pageId) if FileManager.default.fileExists(atPath: audioUrl.path) { return (pending: false, url: audioUrl) } - guard let url = URL(string: "/api/article/\(pageId)/mp3/\(currentVoice)", relativeTo: appEnvironment.serverBaseURL) else { + guard let url = URL(string: "/api/article/\(pageId)/mp3/\(priority)/\(currentVoice)", relativeTo: appEnvironment.serverBaseURL) else { throw BasicError.message(messageText: "Invalid audio URL") } diff --git a/packages/api/src/routers/article_router.ts b/packages/api/src/routers/article_router.ts index 487b32c77..e0f625aad 100644 --- a/packages/api/src/routers/article_router.ts +++ b/packages/api/src/routers/article_router.ts @@ -20,7 +20,6 @@ import { Speech, SpeechState } from '../entity/speech' import { getPageById, updatePage } from '../elastic/pages' import { generateDownloadSignedUrl } from '../utils/uploads' import { enqueueTextToSpeech } from '../utils/createTask' -import { UserPersonalization } from '../entity/user_personalization' import { createPubSubClient } from '../datalayer/pubsub' const logger = buildLogger('app.dispatch') @@ -78,7 +77,7 @@ export function articleRouter() { async (req, res) => { const articleId = req.params.id const outputFormat = req.params.outputFormat - const voice = req.params.voice + const voice = req.params.voice || 'en-US-JennyNeural' const priority = req.params.priority if ( !articleId || @@ -145,17 +144,12 @@ export function articleRouter() { if (!page) { return res.status(404).send('Page not found') } - const userPersonalization = await getRepository( - UserPersonalization - ).findOneBy({ - user: { id: uid }, - }) // initialize state const speech = await getRepository(Speech).save({ user: { id: uid }, elasticPageId: articleId, state: SpeechState.INITIALIZED, - voice: voice || userPersonalization?.speechVoice || 'en-US-JennyNeural', + voice, }) // enqueue a task to convert text to speech const taskName = await enqueueTextToSpeech({