Skip to content

Commit

Permalink
- 新增中文诵读功能,方便临时拼音拼写
Browse files Browse the repository at this point in the history
- 合并查字和查词功能,更加方便高效
- 优化应用细节和体验
  • Loading branch information
iHTCboy committed Jan 27, 2023
1 parent c029393 commit ce72b78
Show file tree
Hide file tree
Showing 14 changed files with 428 additions and 54 deletions.
34 changes: 26 additions & 8 deletions iWuBi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
/* Begin PBXBuildFile section */
2D6303726115B67060D09E85 /* Pods_iWuBiTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5AA5AA6FD67142615E34DC61 /* Pods_iWuBiTests.framework */; };
3719B7397CAA52057F9F1153 /* Pods_iWuBiUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6E83B6E1E91072EBEA6E329 /* Pods_iWuBiUITests.framework */; };
6D0B41282983DDFE006F8C18 /* playvoice@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 6D0B41272983DDFE006F8C18 /* playvoice@2x.png */; };
6D0B41292983DDFE006F8C18 /* playvoice@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 6D0B41272983DDFE006F8C18 /* playvoice@2x.png */; };
6D0B412B2983E336006F8C18 /* TCVoiceUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D0B412A2983E336006F8C18 /* TCVoiceUtils.swift */; };
6D0B412C2983E336006F8C18 /* TCVoiceUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D0B412A2983E336006F8C18 /* TCVoiceUtils.swift */; };
6D0B412E2983FB1E006F8C18 /* IHTCTTSViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D0B412D2983FB1E006F8C18 /* IHTCTTSViewController.swift */; };
6D0B412F2983FB1E006F8C18 /* IHTCTTSViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D0B412D2983FB1E006F8C18 /* IHTCTTSViewController.swift */; };
6D0BF3BF2442186B009EA94B /* IHTC98WordViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB88DEB225B8E340099AC80 /* IHTC98WordViewController.swift */; };
6D0BF3C02442186B009EA94B /* IHTCAboutAppViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB88DE2225B8E340099AC80 /* IHTCAboutAppViewController.swift */; };
6D0BF3C12442186B009EA94B /* IHTCMeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB88DE3225B8E340099AC80 /* IHTCMeViewController.swift */; };
Expand Down Expand Up @@ -293,6 +299,9 @@
4DFAA5851858A4D9CB53BF20 /* libPods-iWuBi-MacCatylyst.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-iWuBi-MacCatylyst.a"; sourceTree = BUILT_PRODUCTS_DIR; };
5AA5AA6FD67142615E34DC61 /* Pods_iWuBiTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_iWuBiTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5FABFA1D936DFEDD99C5AC4A /* Pods_iWuBi.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_iWuBi.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6D0B41272983DDFE006F8C18 /* playvoice@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "playvoice@2x.png"; sourceTree = "<group>"; };
6D0B412A2983E336006F8C18 /* TCVoiceUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TCVoiceUtils.swift; sourceTree = "<group>"; };
6D0B412D2983FB1E006F8C18 /* IHTCTTSViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IHTCTTSViewController.swift; sourceTree = "<group>"; };
6D0BF43E2442186B009EA94B /* iWuBi.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iWuBi.app; sourceTree = BUILT_PRODUCTS_DIR; };
6D0BF441244218FC009EA94B /* iWuBi.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = iWuBi.entitlements; sourceTree = "<group>"; };
6D3B83D5225E238200037787 /* iWuBi-orange-word.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "iWuBi-orange-word.png"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -664,6 +673,7 @@
6DB88DB9225B8E340099AC80 /* Images */ = {
isa = PBXGroup;
children = (
6D0B41272983DDFE006F8C18 /* playvoice@2x.png */,
6DA588A02605FD2400C351C4 /* favorites_normal@2x.png */,
6DA588A12605FD2400C351C4 /* favorites_selected@2x.png */,
6DA588932605FBC600C351C4 /* favorites_normal@3x.png */,
Expand Down Expand Up @@ -758,6 +768,7 @@
6D76E2F022632C1F005EACCA /* IHTCLearnDetailViewController.swift */,
6DB88DE3225B8E340099AC80 /* IHTCMeViewController.swift */,
6DA588AA2605FDC800C351C4 /* IHTCFavoritesListVC.swift */,
6D0B412D2983FB1E006F8C18 /* IHTCTTSViewController.swift */,
6DB88DE2225B8E340099AC80 /* IHTCAboutAppViewController.swift */,
6DB88DE8225B8E340099AC80 /* IHTCAboutAppViewController.xib */,
6DB1AF962278A7640051A288 /* ITAdvancelDetailViewController.swift */,
Expand Down Expand Up @@ -789,6 +800,7 @@
6DB88E1D225B8E720099AC80 /* Common */ = {
isa = PBXGroup;
children = (
6D0B412A2983E336006F8C18 /* TCVoiceUtils.swift */,
6DB88E1E225B8E720099AC80 /* CommonDefine.swift */,
6DB88E1F225B8E720099AC80 /* ITCommonAPI.swift */,
6D76E2B62262C613005EACCA /* IAppleServiceUtil.swift */,
Expand Down Expand Up @@ -984,6 +996,7 @@
6D0BF4002442186B009EA94B /* Main.storyboard in Resources */,
6D0BF4012442186B009EA94B /* tabbar_selected_98@3x.png in Resources */,
6D0BF4022442186B009EA94B /* ITQuestionListViewCell.xib in Resources */,
6D0B41292983DDFE006F8C18 /* playvoice@2x.png in Resources */,
6D0BF4032442186B009EA94B /* iWiBi-orange-icon@2x.png in Resources */,
6D0BF4042442186B009EA94B /* iWuBi-orange-word.png in Resources */,
6D0BF4052442186B009EA94B /* InfoPlist.strings in Resources */,
Expand Down Expand Up @@ -1067,6 +1080,7 @@
6D3B83E0225E27B500037787 /* Main.storyboard in Resources */,
6D76E2D72263118D005EACCA /* tabbar_selected_98@3x.png in Resources */,
6DB88E0C225B8E340099AC80 /* ITQuestionListViewCell.xib in Resources */,
6D0B41282983DDFE006F8C18 /* playvoice@2x.png in Resources */,
6D531B71226379CB00C921B8 /* iWiBi-orange-icon@2x.png in Resources */,
6D3B83D6225E238300037787 /* iWuBi-orange-word.png in Resources */,
6D3B83F2225E307700037787 /* InfoPlist.strings in Resources */,
Expand Down Expand Up @@ -1281,12 +1295,14 @@
6D0BF3D42442186B009EA94B /* ITQuestionListViewCell.swift in Sources */,
6D0BF3D52442186B009EA94B /* ITCopyLabel.swift in Sources */,
6D0BF3D62442186B009EA94B /* IAppleServiceUtil.swift in Sources */,
6D0B412F2983FB1E006F8C18 /* IHTCTTSViewController.swift in Sources */,
6DEB12B8244B536500CD4192 /* SceneDelegate.swift in Sources */,
6D0BF3D72442186B009EA94B /* IHTC86WordViewController.swift in Sources */,
6D0BF3D82442186B009EA94B /* ITBasePushTransitionVC.swift in Sources */,
6D0BF3D92442186B009EA94B /* IHTCWuBiWordViewCell.swift in Sources */,
6D0BF3DA2442186B009EA94B /* IHTCImgModel.swift in Sources */,
6D0BF3DB2442186B009EA94B /* ITScalePopTransition.swift in Sources */,
6D0B412C2983E336006F8C18 /* TCVoiceUtils.swift in Sources */,
6D0BF3DC2442186B009EA94B /* IHTCLearnDetailViewController.swift in Sources */,
6D0BF3DD2442186B009EA94B /* TableHeaderView.swift in Sources */,
6D0BF3DE2442186B009EA94B /* ITPageTitleView.swift in Sources */,
Expand Down Expand Up @@ -1326,12 +1342,14 @@
6DB88E08225B8E340099AC80 /* ITQuestionListViewCell.swift in Sources */,
6DB88E09225B8E340099AC80 /* ITCopyLabel.swift in Sources */,
6D76E2B72262C613005EACCA /* IAppleServiceUtil.swift in Sources */,
6D0B412E2983FB1E006F8C18 /* IHTCTTSViewController.swift in Sources */,
6DEB12B7244B536500CD4192 /* SceneDelegate.swift in Sources */,
6DB88E19225B8E340099AC80 /* IHTC86WordViewController.swift in Sources */,
6DB88E14225B8E340099AC80 /* ITBasePushTransitionVC.swift in Sources */,
6D76E27F225F95F7005EACCA /* IHTCWuBiWordViewCell.swift in Sources */,
6D76E27C225F9064005EACCA /* IHTCImgModel.swift in Sources */,
6DB88E1C225B8E340099AC80 /* ITScalePopTransition.swift in Sources */,
6D0B412B2983E336006F8C18 /* TCVoiceUtils.swift in Sources */,
6D76E2F122632C1F005EACCA /* IHTCLearnDetailViewController.swift in Sources */,
6DB1AF952278A75D0051A288 /* TableHeaderView.swift in Sources */,
6DB88E0A225B8E340099AC80 /* ITPageTitleView.swift in Sources */,
Expand Down Expand Up @@ -1418,7 +1436,7 @@
CODE_SIGN_ENTITLEMENTS = iWuBi/iWuBi.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2023.01.24;
CURRENT_PROJECT_VERSION = 2023.01.27;
DEVELOPMENT_TEAM = 28PV6G96R7;
INFOPLIST_FILE = "$(SRCROOT)/iWuBi/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
Expand All @@ -1427,7 +1445,7 @@
"@executable_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
MARKETING_VERSION = 7.0.0;
MARKETING_VERSION = 7.1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.iHTCboy.iWuBi;
PRODUCT_NAME = iWuBi;
SUPPORTS_MACCATALYST = YES;
Expand All @@ -1447,7 +1465,7 @@
CODE_SIGN_ENTITLEMENTS = iWuBi/iWuBi.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2023.01.24;
CURRENT_PROJECT_VERSION = 2023.01.27;
DEVELOPMENT_TEAM = 28PV6G96R7;
INFOPLIST_FILE = "$(SRCROOT)/iWuBi/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
Expand All @@ -1456,7 +1474,7 @@
"@executable_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
MARKETING_VERSION = 7.0.0;
MARKETING_VERSION = 7.1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.iHTCboy.iWuBi;
PRODUCT_NAME = iWuBi;
SUPPORTS_MACCATALYST = YES;
Expand Down Expand Up @@ -1593,7 +1611,7 @@
CODE_SIGN_ENTITLEMENTS = iWuBi/iWuBi.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2023.01.24;
CURRENT_PROJECT_VERSION = 2023.01.27;
DEVELOPMENT_TEAM = 28PV6G96R7;
INFOPLIST_FILE = iWuBi/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
Expand All @@ -1602,7 +1620,7 @@
"@executable_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
MARKETING_VERSION = 7.0.0;
MARKETING_VERSION = 7.1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.iHTCboy.iWuBi;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
Expand All @@ -1622,7 +1640,7 @@
CODE_SIGN_ENTITLEMENTS = iWuBi/iWuBi.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2023.01.24;
CURRENT_PROJECT_VERSION = 2023.01.27;
DEVELOPMENT_TEAM = 28PV6G96R7;
INFOPLIST_FILE = iWuBi/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
Expand All @@ -1631,7 +1649,7 @@
"@executable_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
MARKETING_VERSION = 7.0.0;
MARKETING_VERSION = 7.1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.iHTCboy.iWuBi;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
Expand Down
98 changes: 98 additions & 0 deletions iWuBi/Common/TCVoiceUtils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//
// TCVoiceUtils.swift
// iEnglish
//
// Created by HTC on 2023/1/26.
// Copyright © 2023 iHTCboy. All rights reserved.
//

import Foundation
import AVFoundation

class TCVoiceUtils: NSObject {

static let shared = TCVoiceUtils()
// 参数
static var setupSuccess: Bool = false
static var completion: (() -> Void)?

// TTS
static var synthesizer: AVSpeechSynthesizer = AVSpeechSynthesizer()
static var utterance:AVSpeechUtterance = AVSpeechUtterance(string: "")

static func playTTS(text: String, completion: (() -> Void)? = nil) {

// 设置声音
if !TCVoiceUtils.setupSuccess {
TCVoiceUtils.setupSuccess = true
TCVoiceUtils.setupVoiceSystem(allowVoice: true)
}

if synthesizer.isSpeaking {
utterance.volume = 0
synthesizer.delegate = nil
synthesizer.stopSpeaking(at: AVSpeechBoundary.immediate)
}

TCVoiceUtils.completion = completion

synthesizer.delegate = TCVoiceUtils.shared
utterance = AVSpeechUtterance(string: text)
utterance.voice = AVSpeechSynthesisVoice(language:"zh-CN")
// utterance.volume = 1
utterance.rate = AVSpeechUtteranceDefaultSpeechRate // 范围:0~1
synthesizer.speak(utterance)
}

@discardableResult
static func pauseTTS() -> Bool {
return synthesizer.pauseSpeaking(at: AVSpeechBoundary.word)
}

@discardableResult
static func continueTTS() -> Bool {
return synthesizer.continueSpeaking()
}

static func stopTTS() {
if synthesizer.isSpeaking {
utterance.volume = 0
synthesizer.delegate = nil
synthesizer.stopSpeaking(at: AVSpeechBoundary.immediate)
}
}

static func playSound(audioPath: String, soundId: inout SystemSoundID) {
let fileUrl = URL.init(fileURLWithPath: audioPath)

AudioServicesCreateSystemSoundID(fileUrl as CFURL, &soundId)

AudioServicesAddSystemSoundCompletion(soundId, nil, nil, {
(soundID:SystemSoundID, _:UnsafeMutableRawPointer?) in
}, nil)

AudioServicesPlaySystemSound(soundId)
}

//设置声音模式(是否设备静音也播放)
/// - Parameter allowVoice: 是否设备静音也播放
static func setupVoiceSystem(allowVoice: Bool) {
if allowVoice {
let audioSession = AVAudioSession.sharedInstance()
try? audioSession.setCategory(AVAudioSession.Category.playback)
try? audioSession.setActive(true, options: AVAudioSession.SetActiveOptions(rawValue: 0))
} else {
let audioSession = AVAudioSession.sharedInstance()
try? audioSession.setCategory(AVAudioSession.Category.ambient)
try? audioSession.setActive(true, options: AVAudioSession.SetActiveOptions(rawValue: 0))
}
}
}

extension TCVoiceUtils: AVSpeechSynthesizerDelegate {

func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) {
// 结束播放
TCVoiceUtils.completion?()
}
}
Binary file added iWuBi/Resource/Images/playvoice@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion iWuBi/View/ITListTitleViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class ITListTitleViewCell: UITableViewCell {

@IBOutlet weak var versionLbl: UILabel!


@IBOutlet weak var wordLbl: ITCopyLabel!

var voiceCallback: (() -> Void)?

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
Expand All @@ -34,4 +35,7 @@ class ITListTitleViewCell: UITableViewCell {
// Configure the view for the selected state
}

@IBAction func clickedVoiceButton(_ sender: UIButton) {
voiceCallback?()
}
}
Loading

0 comments on commit ce72b78

Please sign in to comment.