我使用AVAudioPlayer播放声音,但在播放时,音量非常低。
我完成了搜索,发现了很多关于添加会话属性或会话类别的代码,但我想知道如何使用它。
-(void) playVoice: (NSString *) path
{
if([path isEqualToString:@""] == NO)
{
//Initialize the AVAudioPlayer.
NSData *soundData= [NSData dataWithContentsOfFile:path];
NSError *error;
audioPlayer= [[AVAudioPlayer alloc] initWithData:soundData error:&error];
if (error)
{
NSLog(@"Error in audioPlayer: %@",
[error localizedDescription]);
} else {
audioPlayer.delegate = self;
NSLog(@"total time=%f", self.audioPlayer.currentTime);
self.PlayStatusSlider.maximumValue= audioPlayer.duration;
myTimer= [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(changeAudioProgress) userInfo:nil repeats:YES];
[audioPlayer prepareToPlay];
[audioPlayer setVolume:1.0];
[audioPlayer play];
}
}else{
// NSLog(@"ErrorDownloading");
}
}
- (void) configureAVAudioSession
{
//get your app's audioSession singleton object
AVAudioSession* session = [AVAudioSession sharedInstance];
//error handling
BOOL success;
NSError* error;
//set the audioSession category.
//Needs to be Record or PlayAndRecord to use audioRouteOverride:
success = [session setCategory:AVAudioSessionCategoryPlayAndRecord
error:&error];
if (!success) NSLog(@"AVAudioSession error setting category:%@",error);
//set the audioSession override
success = [session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker
error:&error];
if (!success) NSLog(@"AVAudioSession error overrideOutputAudioPort:%@",error);
//activate the audio session
success = [session setActive:YES error:&error];
if (!success) NSLog(@"AVAudioSession error activating: %@",error);
else NSLog(@"audioSession active");
}
但它不适合我。女巫部分错了?我应该如何使用它?
答案 0 :(得分:1)
您必须将音频会话默认设置为扬声器。 对于现在遇到这个问题的任何人:
private var configureAudioSessionError:NSError?
def getAllWindows(L):
tracker = set()
for w in range(1, len(L)+1):
for i in range(len(L)-w+1):
sub_window = L[i:i+w]
if sub_window not in tracker:
tracker.add(sub_window)
yield sub_window
lookup_list = ['red', 'hello', 'how are you', 'hey', 'deployed']
lookup_set = set(lookup_list)
text = 'hello, This is shared right? how are you doing tonight'
result = [sub_window for sub_window in getAllWindows(text) if sub_window in lookup_list]
print(result)
#Output:
['red', 'hello', 'how are you']