Voice recognition improvements. Closes #8 #22

This commit is contained in:
Kylmakalle 2025-01-17 17:26:49 +02:00
parent 07e3997147
commit bfb18929f2
4 changed files with 16 additions and 2 deletions

View File

@ -50,6 +50,7 @@ private func transcribeAudio(path: String, locale: String) -> Signal<Transcripti
}
speechRecognizer.supportsOnDeviceRecognition = true
}
speechRecognizer.defaultTaskHint = .dictation
let tempFilePath = NSTemporaryDirectory() + "/\(UInt64.random(in: 0 ... UInt64.max)).m4a"
let _ = try? FileManager.default.copyItem(atPath: path, toPath: tempFilePath)

View File

@ -450,7 +450,8 @@ public final class ChatMessageInteractiveFileNode: ASDisplayNode {
guard let result = result else {
return .single(nil)
}
return transcribeAudio(path: result, appLocale: appLocale)
return transcribeAudio(path: result, appLocale: arguments.controllerInteraction.sgGetChatPredictedLang() ?? appLocale)
}
self.transcribeDisposable = (signal
@ -802,7 +803,7 @@ public final class ChatMessageInteractiveFileNode: ASDisplayNode {
}
let currentTime = Int32(Date().timeIntervalSince1970)
if transcribedText == nil, let cooldownUntilTime = arguments.associatedData.audioTranscriptionTrial.cooldownUntilTime, cooldownUntilTime > currentTime {
if transcribedText == nil, let cooldownUntilTime = arguments.associatedData.audioTranscriptionTrial.cooldownUntilTime, cooldownUntilTime > currentTime, { return false }() /* MARK: Swiftgram */ {
updatedAudioTranscriptionState = .locked
}

View File

@ -171,6 +171,7 @@ public final class ChatControllerInteraction: ChatControllerInteractionProtocol
public let openMessage: (Message, OpenMessageParams) -> Bool
// MARK: Swiftgram
public let sgStartMessageEdit: (Message) -> Void
public let sgGetChatPredictedLang: () -> String?
public let openPeer: (EnginePeer, ChatControllerInteractionNavigateToPeer, MessageReference?, OpenPeerSource) -> Void
public let openPeerMention: (String, Promise<Bool>?) -> Void
public let openMessageContextMenu: (Message, Bool, ASDisplayNode, CGRect, UIGestureRecognizer?, CGPoint?) -> Void
@ -305,6 +306,7 @@ public final class ChatControllerInteraction: ChatControllerInteractionProtocol
public init(
openMessage: @escaping (Message, OpenMessageParams) -> Bool,
sgGetChatPredictedLang: @escaping () -> String? = { return nil },
sgStartMessageEdit: @escaping (Message) -> Void = { _ in },
openPeer: @escaping (EnginePeer, ChatControllerInteractionNavigateToPeer, MessageReference?, OpenPeerSource) -> Void,
openPeerMention: @escaping (String, Promise<Bool>?) -> Void,
@ -419,6 +421,7 @@ public final class ChatControllerInteraction: ChatControllerInteractionProtocol
presentationContext: ChatPresentationContext
) {
self.openMessage = openMessage
self.sgGetChatPredictedLang = sgGetChatPredictedLang
self.sgStartMessageEdit = sgStartMessageEdit
self.openPeer = openPeer
self.openPeerMention = openPeerMention

View File

@ -1494,6 +1494,15 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
return rect
}
))
}, sgGetChatPredictedLang: { [weak self] in
if let strongSelf = self {
var result: String?
if let chatPeerId = strongSelf.chatLocation.peerId {
result = SGSimpleSettings.shared.outgoingLanguageTranslation[SGSimpleSettings.makeOutgoingLanguageTranslationKey(accountId: strongSelf.context.account.peerId.id._internalGetInt64Value(), peerId: chatPeerId.id._internalGetInt64Value())]
}
return result ?? strongSelf.predictedChatLanguage
}
return nil
}, sgStartMessageEdit: { [weak self] message in
if let strongSelf = self {
strongSelf.interfaceInteraction?.setupEditMessage(message.id, { _ in })