我正在开发一款TextToSpeech应用.我在a中写了一段UITextField,然后按下Speak按钮.声音根据文中所写的文字播放UITextField.

但是,当应用程序处于后台模式时,音频将停止播放.如何在后台模式下继续播放声音?类似于音频播放器如何在后台播放歌曲.
我使用以下代码进行文本到语音转换:
#import "ViewController.h"
#import "Google_TTS_BySham.h"
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
@property (nonatomic,strong)Google_TTS_BySham *google_TTS_BySham;
@property (nonatomic,strong)IBOutlet UITextField *txtString;
@end
@implementation ViewController
#pragma mark - View Life Cycle
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark - Button Tapped event
- (IBAction)btnSpeakTapped:(id)sender{
NSString *str = [NSString stringWithFormat:@"%@",_txtString.text];
self.google_TTS_BySham = [[Google_TTS_BySham alloc] init];
[self.google_TTS_BySham speak:str];
}
Run Code Online (Sandbox Code Playgroud)