public async Task PlaySampleVoice(string username, string instance, VoiceProfileType type, string sampleText, CancellationToken cancellationToken) { var accountIdentifier = new AccountIdentifier(new Username(username), new Instance(instance)); var profile = type switch { VoiceProfileType.MastodonStatus => await _voiceProfileRepository .GetVoiceProfile <VoiceProfile.MastodonStatusVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MastodonSensitiveStatus => await _voiceProfileRepository .GetVoiceProfile <VoiceProfile.MastodonSensitiveStatusVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MastodonBoostedStatus => await _voiceProfileRepository .GetVoiceProfile <VoiceProfile.MastodonBoostedStatusVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MastodonBoostedSensitiveStatus => await _voiceProfileRepository .GetVoiceProfile <VoiceProfile.MastodonBoostedSensitiveStatusVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MastodonFollowNotification => await _repository .GetVoiceProfile <VoiceProfile.MastodonFollowNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MastodonFollowRequestNotification => await _repository .GetVoiceProfile <VoiceProfile.MastodonFollowRequestNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MastodonMentionNotification => await _repository .GetVoiceProfile <VoiceProfile.MastodonMentionNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MastodonSensitiveMentionNotification => await _repository .GetVoiceProfile <VoiceProfile.MastodonSensitiveMentionNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MastodonReblogNotification => await _repository .GetVoiceProfile <VoiceProfile.MastodonReblogNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MastodonSensitiveReblogNotification => await _repository .GetVoiceProfile <VoiceProfile.MastodonSensitiveReblogNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MastodonFavoriteNotification => await _repository .GetVoiceProfile <VoiceProfile.MastodonFavoriteNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MastodonSensitiveFavoriteNotification => await _repository .GetVoiceProfile <VoiceProfile.MastodonSensitiveFavoriteNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeyNote => await _repository .GetVoiceProfile <VoiceProfile.MisskeyNoteVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeySensitiveNote => await _repository .GetVoiceProfile <VoiceProfile.MisskeySensitiveNoteVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeyRenote => await _repository .GetVoiceProfile <VoiceProfile.MisskeyRenoteVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeySensitiveRenote => await _repository .GetVoiceProfile <VoiceProfile.MisskeySensitiveRenoteVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeyReactionNotification => await _repository .GetVoiceProfile <VoiceProfile.MisskeyReactionNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeySensitiveReactionNotification => await _repository .GetVoiceProfile <VoiceProfile.MisskeySensitiveReactionNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeyReplyNotification => await _repository .GetVoiceProfile <VoiceProfile.MisskeyReplyNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeySensitiveReplyNotification => await _repository .GetVoiceProfile <VoiceProfile.MisskeySensitiveReplyNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeyRenoteNotification => await _repository .GetVoiceProfile <VoiceProfile.MisskeyRenoteNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeySensitiveRenoteNotification => await _repository .GetVoiceProfile <VoiceProfile.MisskeySensitiveRenoteNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeyQuoteNotification => await _repository .GetVoiceProfile <VoiceProfile.MisskeyQuoteNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeySensitiveQuoteNotification => await _repository .GetVoiceProfile <VoiceProfile.MisskeySensitiveQuoteNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeyMentionNotification => await _repository .GetVoiceProfile <VoiceProfile.MisskeyMentionNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeySensitiveMentionNotification => await _repository .GetVoiceProfile <VoiceProfile.MisskeySensitiveMentionNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeyFollowNotification => await _repository .GetVoiceProfile <VoiceProfile.MisskeyFollowNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeyFollowRequestAcceptedNotification => await _repository .GetVoiceProfile <VoiceProfile.MisskeyFollowRequestAcceptedNotificationVoiceProfile>(accountIdentifier, cancellationToken), VoiceProfileType.MisskeyReceiveFollowRequestNotification => await _repository .GetVoiceProfile <VoiceProfile.MisskeyReceiveFollowRequestNotificationVoiceProfile>(accountIdentifier, cancellationToken), _ => throw new InvalidProgramException(), }; var voiceParameter = await _voiceParameterChangeNotifierRepository.GetInstance(cancellationToken); voiceParameter.SetCurrentProfile(profile); await _speakText.SpeakText(sampleText, cancellationToken); }
public async Task StartReading(CancellationToken cancellationToken) { var container = _containerRepository.GetContainer(); var voiceParameter = await _voiceParameterChangeNotifierRepository.GetInstance(cancellationToken); while (!cancellationToken.IsCancellationRequested) { var item = await container.PeekAsync(cancellationToken); var tmp = item.AccountIdentifier.Value.Split('@'); var username = tmp[0] !; var instance = tmp[1] !; var accountIdentifier = new AccountIdentifier(new Username(username), new Instance(instance)); VoiceProfile profile; switch (item) { case ReadingTextItem.MastodonStatusReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MastodonStatusVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MastodonSensitiveStatusReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MastodonSensitiveStatusVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MastodonBoostedStatusReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MastodonBoostedStatusVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MastodonBoostedSensitiveStatusReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MastodonBoostedSensitiveStatusVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MastodonFollowNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MastodonFollowNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MastodonFollowRequestNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MastodonFollowRequestNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MastodonMentionNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MastodonMentionNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MastodonSensitiveMentionNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MastodonSensitiveMentionNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MastodonReblogNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MastodonReblogNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MastodonSensitiveReblogNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MastodonSensitiveReblogNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MastodonFavoriteNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MastodonFavoriteNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MastodonSensitiveFavoriteNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MastodonSensitiveFavoriteNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeyNoteReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeyNoteVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeySensitiveNoteReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeySensitiveNoteVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeyRenoteReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeyRenoteVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeySensitiveRenoteReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeySensitiveRenoteVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeyReactionNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeyReactionNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeySensitiveReactionNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeySensitiveReactionNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeyReplyNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeyReplyNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeySensitiveReplyNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeySensitiveReplyNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeyRenoteNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeyRenoteNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeySensitiveRenoteNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeySensitiveRenoteNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeyQuoteNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeyQuoteNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeySensitiveQuoteNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeySensitiveQuoteNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeyMentionNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeyMentionNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeySensitiveMentionNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeySensitiveMentionNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeyFollowNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeyFollowNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeyFollowRequestAcceptedNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeyFollowRequestAcceptedNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; case ReadingTextItem.MisskeyReceiveFollowRequestNotificationReadingTextItem: profile = await _voiceProfileRepository.GetVoiceProfile <VoiceProfile.MisskeyReceiveFollowRequestNotificationVoiceProfile>( accountIdentifier, cancellationToken); voiceParameter.SetCurrentProfile(profile); break; } try { _changeImage.OpenMouth(); var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); await Task.WhenAny(_speakText.SpeakText(item.Text, cts.Token), container.Overflow(cts.Token)); cts.Cancel(true); cts.Dispose(); } finally { _changeImage.CloseMouth(); container.RemoveFirstItem(); } } }