Skip to content

Commit

Permalink
Merge branch 'fe-unit-test' of https://github.com/harmony-one/x into …
Browse files Browse the repository at this point in the history
…fe-unit-test
  • Loading branch information
fegloff committed Nov 13, 2023
2 parents 06f7813 + cabc1df commit 1b985ad
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 144 deletions.
2 changes: 1 addition & 1 deletion progress/sergey-karasev.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2023-11-10 Fri: Working on [truncating the accumulating context to a maximum of 512 characters](https://github.com/harmony-one/x/pull/159) and adding unit tests for the "limiter", [added the same logic to harmony one bot](https://github.com/harmony-one/HarmonyOneBot/pull/343)
2023-11-10 Fri: Working on [truncating the accumulating context to a maximum of 512 characters](https://github.com/harmony-one/x/pull/159) and adding unit tests for the "limiter"

2023-11-09 Thu: I have added [a window to display a link to the application](https://github.com/harmony-one/x/pull/142) (share feature) after the user taps "new session" button for the seventh time, also [added a throttler](https://github.com/harmony-one/x/pull/144) to the reset session function (in order not to interrupt the greeting). Clarified the code regarding tap-to-speak and [fixed the play-pause button state](https://github.com/harmony-one/x/pull/149)

Expand Down
2 changes: 1 addition & 1 deletion progress/yuriy-menkov.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2023-11-10 Fri: [Resolved](https://github.com/harmony-one/x/pull/161) issue with long press actions (Ensure long press actions do not trigger tap actions vice versa). Working on tracking active using app time and showing suggestions to share with friends and share on Twitter.
2023-11-10 Fri: Resolved issue with long press actions (Ensure long press actions do not trigger tap actions vice versa). Working on tracking active using app time and showing suggestions to share with friends and share on Twitter.

2023-11-9 Thu: [Added](https://github.com/harmony-one/x/pull/148/files) the ability to repeat the current session to resolve repeat bug (When hitting "Repeat" during the first stream, it says "Hey" while the stream is going. It should just start again from the beginning instead.)

Expand Down
24 changes: 12 additions & 12 deletions voice/voice-ai/Voice AI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@
B36367562AFC69F2000409FC /* RandomFactTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B31CDCE62AFC644D00AB39EE /* RandomFactTests.swift */; };
B36367572AFC6A04000409FC /* MockGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F1150D2AF825F700BC191C /* MockGenerator.swift */; };
B38ADB9D2AFE0A0F006BDC93 /* AppConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = F72708412AFD672E000DE81D /* AppConfig.plist */; };
B3C083B32AF1BADB0069232C /* OpenAITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3C083B22AF1BADB0069232C /* OpenAITests.swift */; };
B3C0FE4B2AFEC68800B712E7 /* IAPTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3C0FE4A2AFEC68800B712E7 /* IAPTests.swift */; };
B3C083B32AF1BADB0069232C /* MessageContextTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3C083B22AF1BADB0069232C /* MessageContextTests.swift */; };
B3D0A3442AF29B1B00E8B0DA /* MockNetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D0A3432AF29B1B00E8B0DA /* MockNetworkService.swift */; };
B91681282AFBA3A80006E463 /* ReviewRequester.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9B331A02AFB803500F6A9C9 /* ReviewRequester.swift */; };
B919B7BF2AF3C3F7006335D1 /* AudioEngineAndSessionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B919B7BE2AF3C3F7006335D1 /* AudioEngineAndSessionTests.swift */; };
Expand Down Expand Up @@ -121,7 +120,6 @@
B9B331A32AFB849000F6A9C9 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B9B331A22AFB849000F6A9C9 /* StoreKit.framework */; };
B9BA337E2AE683EF00D7756D /* AudioPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9BA337D2AE683EF00D7756D /* AudioPlayer.swift */; };
B9C4A81F2AEE594900327529 /* MockSpeechRecognition.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9C4A81E2AEE594900327529 /* MockSpeechRecognition.swift */; };
B9C4A8212AEE612A00327529 /* MockTextToSpeechConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9C4A8202AEE612A00327529 /* MockTextToSpeechConverter.swift */; };
B9C4A8282AEE867A00327529 /* ActionHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9C4A8262AEE861C00327529 /* ActionHandler.swift */; };
B9C4A8292AEE867E00327529 /* ActionHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9C4A8262AEE861C00327529 /* ActionHandler.swift */; };
B9C4A82A2AEE95C900327529 /* SpeechRecognition.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9AD50532ADFE8A0006F18A1 /* SpeechRecognition.swift */; };
Expand Down Expand Up @@ -157,6 +155,8 @@
F61049122AF02DF50087F745 /* SwiftyJSON in Frameworks */ = {isa = PBXBuildFile; productRef = F61049112AF02DF50087F745 /* SwiftyJSON */; };
F67E43322AFAC166001B72CD /* SentrySwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = F67E43312AFAC166001B72CD /* SentrySwiftUI */; };
F67E43342AFAC16C001B72CD /* Sentry in Frameworks */ = {isa = PBXBuildFile; productRef = F67E43332AFAC16C001B72CD /* Sentry */; };
F723CC1F2AFECE2000B2A23A /* TextToSpeechConverterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F723CC1E2AFECE2000B2A23A /* TextToSpeechConverterTests.swift */; };
F723CC212AFEFFA400B2A23A /* MockAVSpeechSynthesizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F723CC202AFEFFA400B2A23A /* MockAVSpeechSynthesizer.swift */; };
F72708422AFD672E000DE81D /* AppConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = F72708412AFD672E000DE81D /* AppConfig.plist */; };
F7C16FE82AFC576000D11529 /* ThemeManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B346DF772AF562020023FC87 /* ThemeManager.swift */; };
F7F115052AF8173300BC191C /* SpeechRecognitionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F114F52AF8172800BC191C /* SpeechRecognitionTests.swift */; };
Expand Down Expand Up @@ -233,8 +233,7 @@
B346DF772AF562020023FC87 /* ThemeManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeManager.swift; sourceTree = "<group>"; };
B3B3BA792AFB40A300D8F8C6 /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = "<group>"; };
B3C083B12AF1948D0069232C /* OpenAIService.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; name = OpenAIService.xctestplan; path = x/OpenAIService.xctestplan; sourceTree = SOURCE_ROOT; };
B3C083B22AF1BADB0069232C /* OpenAITests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenAITests.swift; sourceTree = "<group>"; };
B3C0FE4A2AFEC68800B712E7 /* IAPTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IAPTests.swift; sourceTree = "<group>"; };
B3C083B22AF1BADB0069232C /* MessageContextTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageContextTests.swift; sourceTree = "<group>"; };
B3D0A3432AF29B1B00E8B0DA /* MockNetworkService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockNetworkService.swift; sourceTree = "<group>"; };
B919B7BE2AF3C3F7006335D1 /* AudioEngineAndSessionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioEngineAndSessionTests.swift; sourceTree = "<group>"; };
B930AADC2ADE2DE5009F9F8C /* Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
Expand All @@ -261,7 +260,6 @@
B9B331A22AFB849000F6A9C9 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.0.sdk/System/Library/Frameworks/StoreKit.framework; sourceTree = DEVELOPER_DIR; };
B9BA337D2AE683EF00D7756D /* AudioPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayer.swift; sourceTree = "<group>"; };
B9C4A81E2AEE594900327529 /* MockSpeechRecognition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockSpeechRecognition.swift; sourceTree = "<group>"; };
B9C4A8202AEE612A00327529 /* MockTextToSpeechConverter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockTextToSpeechConverter.swift; sourceTree = "<group>"; };
B9C4A8262AEE861C00327529 /* ActionHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionHandler.swift; sourceTree = "<group>"; };
B9CE36E92AFD0365009999CF /* TimerManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimerManager.swift; sourceTree = "<group>"; };
CD0D13342ADA73B300031EDD /* Voice AI.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Voice AI.app"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -280,6 +278,8 @@
CD0D13682ADA74D100031EDD /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.0.sdk/System/Library/Frameworks/AVFoundation.framework; sourceTree = DEVELOPER_DIR; };
CD0D136A2ADB28CE00031EDD /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo.png; sourceTree = SOURCE_ROOT; };
F61049092AF02D820087F745 /* OpenAIStreamService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenAIStreamService.swift; sourceTree = "<group>"; };
F723CC1E2AFECE2000B2A23A /* TextToSpeechConverterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextToSpeechConverterTests.swift; sourceTree = "<group>"; };
F723CC202AFEFFA400B2A23A /* MockAVSpeechSynthesizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockAVSpeechSynthesizer.swift; sourceTree = "<group>"; };
F72708412AFD672E000DE81D /* AppConfig.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = AppConfig.plist; sourceTree = "<group>"; };
F7F114F52AF8172800BC191C /* SpeechRecognitionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpeechRecognitionTests.swift; sourceTree = "<group>"; };
F7F114F62AF8172800BC191C /* PermissionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PermissionTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -597,14 +597,14 @@
F7F114FB2AF8172800BC191C /* VibrationManagerTests.swift */,
CD0D134C2ADA73B400031EDD /* ActionHandlerTests.swift */,
B9C4A81E2AEE594900327529 /* MockSpeechRecognition.swift */,
B9C4A8202AEE612A00327529 /* MockTextToSpeechConverter.swift */,
B3C083B22AF1BADB0069232C /* OpenAITests.swift */,
B3C083B22AF1BADB0069232C /* MessageContextTests.swift */,
B3D0A3432AF29B1B00E8B0DA /* MockNetworkService.swift */,
B919B7BE2AF3C3F7006335D1 /* AudioEngineAndSessionTests.swift */,
F7F1150D2AF825F700BC191C /* MockGenerator.swift */,
B31CDCE62AFC644D00AB39EE /* RandomFactTests.swift */,
6E35CB4A2AFE86130004D2D2 /* OpenAIUtilsTests.swift */,
B3C0FE4A2AFEC68800B712E7 /* IAPTests.swift */,
F723CC1E2AFECE2000B2A23A /* TextToSpeechConverterTests.swift */,
F723CC202AFEFFA400B2A23A /* MockAVSpeechSynthesizer.swift */,
);
path = xTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -986,6 +986,7 @@
F7F1150C2AF8173300BC191C /* DashboardViewTests.swift in Sources */,
F7F115062AF8173300BC191C /* StringTests.swift in Sources */,
B31CDCE42AFC565400AB39EE /* ThemeManager.swift in Sources */,
F723CC212AFEFFA400B2A23A /* MockAVSpeechSynthesizer.swift in Sources */,
B9C4A81F2AEE594900327529 /* MockSpeechRecognition.swift in Sources */,
F610490B2AF02D820087F745 /* OpenAIStreamService.swift in Sources */,
B36367562AFC69F2000409FC /* RandomFactTests.swift in Sources */,
Expand All @@ -996,6 +997,7 @@
B9C4A8322AEE96B600327529 /* Usage.swift in Sources */,
F7F1150A2AF8173300BC191C /* VibrationManagerTests.swift in Sources */,
B36367572AFC6A04000409FC /* MockGenerator.swift in Sources */,
F723CC1F2AFECE2000B2A23A /* TextToSpeechConverterTests.swift in Sources */,
A40CFCE42AF98BB700E02128 /* RandomFact.swift in Sources */,
B9C4A8312AEE96B300327529 /* OpenAIResponse.swift in Sources */,
F7F115082AF8173300BC191C /* AudioPlayerTests.swift in Sources */,
Expand All @@ -1005,13 +1007,11 @@
6E35CB4C2AFE86130004D2D2 /* OpenAIUtilsTests.swift in Sources */,
B31CDCE52AFC565800AB39EE /* Theme.swift in Sources */,
B9C4A82A2AEE95C900327529 /* SpeechRecognition.swift in Sources */,
B3C0FE4B2AFEC68800B712E7 /* IAPTests.swift in Sources */,
B9C4A8212AEE612A00327529 /* MockTextToSpeechConverter.swift in Sources */,
F7C16FE82AFC576000D11529 /* ThemeManager.swift in Sources */,
F7F115072AF8173300BC191C /* PermissionTests.swift in Sources */,
6E53AF4C2AF012760022A8F2 /* GridButton.swift in Sources */,
B9C4A82F2AEE96AE00327529 /* Choices.swift in Sources */,
B3C083B32AF1BADB0069232C /* OpenAITests.swift in Sources */,
B3C083B32AF1BADB0069232C /* MessageContextTests.swift in Sources */,
B9C4A82C2AEE967200327529 /* AudioPlayer.swift in Sources */,
6E53AF512AF012A40022A8F2 /* Color.swift in Sources */,
);
Expand Down
15 changes: 13 additions & 2 deletions voice/voice-ai/x/Converter/TextToSpeechConverter.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import AVFoundation
import Foundation

protocol TextToSpeechConverterProtocol {
func convertTextToSpeech(text: String, pitch: Float, volume: Float)
func stopSpeech()
func pauseSpeech()
func continueSpeech()
}

// TextToSpeechConverter class responsible for converting text to speech
class TextToSpeechConverter {
class TextToSpeechConverter: TextToSpeechConverterProtocol {
// AVSpeechSynthesizer instance to handle speech synthesis
let synthesizer = AVSpeechSynthesizer()
var synthesizer = AVSpeechSynthesizer()

// Function to convert text to speech with customizable pitch and volume parameters
func convertTextToSpeech(text: String, pitch: Float = 1.0, volume: Float = 1.0) {
Expand Down Expand Up @@ -42,6 +49,10 @@ class TextToSpeechConverter {
// Check if the synthesizer is currently speaking and pause it immediately
if synthesizer.isSpeaking {
synthesizer.pauseSpeaking(at: .immediate)
print("Speech paused.")
Thread.sleep(forTimeInterval: 1.0)
} else {
print("Speech is not speaking.")
}
}

Expand Down
1 change: 1 addition & 0 deletions voice/voice-ai/x/SpeechRecognition/SpeechRecognition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class SpeechRecognition: NSObject, ObservableObject, SpeechRecognitionProtocol {
recognitionTaskCanceled = nil
// General cleanup process
let inputNode = audioEngine.inputNode
recognitionRequest?.endAudio()
inputNode.removeTap(onBus: 0)
recognitionRequest = nil
recognitionTask = nil
Expand Down
21 changes: 0 additions & 21 deletions voice/voice-ai/xTests/IAPTests.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,59 +24,6 @@ class OpenAIServiceTests: XCTestCase {
}
}

class OpenAIResponseTests: XCTestCase {

func testInit() throws {
// Given
let json = """
{
"id": "123",
"object": "response",
"created": 1635790771,
"model": "gpt-3.5-turbo",
"choices": [
{
"message": {
"role": "user",
"content": "Hi"
},
"finish_reason": "OK",
"index": 1
},
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 50,
"total_tokens": 60
}
}
"""

// When
let jsonData = Data(json.utf8)
let response = try JSONDecoder().decode(OpenAIResponse.self, from: jsonData)

// Then
XCTAssertEqual(response.id, "123")
XCTAssertEqual(response.object, "response")
XCTAssertEqual(response.created, 1635790771)
XCTAssertEqual(response.model, "gpt-3.5-turbo")

XCTAssertEqual(response.choices?.count, 1)
XCTAssertEqual(response.choices?[0].message?.role, "user")
XCTAssertEqual(response.choices?[0].message?.content, "Hi")

XCTAssertNotNil(response.usage)
XCTAssertEqual(response.usage?.prompt_tokens, 10)
XCTAssertEqual(response.usage?.completion_tokens, 50)
XCTAssertEqual(response.usage?.total_tokens, 60)
}

// Add more test cases as needed

}

class MessageTests: XCTestCase {
func testInitialization() {
// Test initializing a Message instance
Expand Down
32 changes: 32 additions & 0 deletions voice/voice-ai/xTests/MockAVSpeechSynthesizer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import AVFoundation

class MockAVSpeechSynthesizer: AVSpeechSynthesizer {
var isSpeakingStub: Bool = false
var isPausedStub: Bool = false

override var isSpeaking: Bool {
return isSpeakingStub
}

override var isPaused: Bool {
return isPausedStub
}

override func pauseSpeaking(at boundary: AVSpeechBoundary) -> Bool {
// Simulate the pausing behavior by setting isPausedStub to true
isPausedStub = true
return true // Return true to indicate success
}

override func continueSpeaking() -> Bool {
// Simulate the continueSpeaking behavior by setting isPausedStub to false
isPausedStub = false
return true // Return true to indicate success
}

override func stopSpeaking(at boundary: AVSpeechBoundary) -> Bool {
// Simulate the stopSpeaking behavior by setting isSpeakingStub to false
isSpeakingStub = false
return true // Return true to indicate success
}
}
31 changes: 0 additions & 31 deletions voice/voice-ai/xTests/MockTextToSpeechConverter.swift

This file was deleted.

Loading

0 comments on commit 1b985ad

Please sign in to comment.