示例#1
0
        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);
        }
示例#2
0
        public async Task SetVoiceProfile(string username, string instance, VoiceProfileType type, VoiceProfileData data, CancellationToken cancellationToken)
        {
            var id      = new AccountIdentifier(new Username(username), new Instance(instance));
            var profile = type switch
            {
                VoiceProfileType.MastodonStatus => await _repository
                .GetVoiceProfile <VoiceProfile.MastodonStatusVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MastodonSensitiveStatus => await _repository
                .GetVoiceProfile <VoiceProfile.MastodonSensitiveStatusVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MastodonBoostedStatus => await _repository
                .GetVoiceProfile <VoiceProfile.MastodonBoostedStatusVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MastodonBoostedSensitiveStatus => await _repository
                .GetVoiceProfile <VoiceProfile.MastodonBoostedSensitiveStatusVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MastodonFollowNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MastodonFollowNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MastodonFollowRequestNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MastodonFollowRequestNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MastodonMentionNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MastodonMentionNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MastodonSensitiveMentionNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MastodonSensitiveMentionNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MastodonReblogNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MastodonReblogNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MastodonSensitiveReblogNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MastodonSensitiveReblogNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MastodonFavoriteNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MastodonFavoriteNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MastodonSensitiveFavoriteNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MastodonSensitiveFavoriteNotificationVoiceProfile>(id, cancellationToken),

                VoiceProfileType.MisskeyNote => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeyNoteVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeySensitiveNote => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeySensitiveNoteVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeyRenote => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeyRenoteVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeySensitiveRenote => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeySensitiveRenoteVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeyReactionNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeyReactionNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeySensitiveReactionNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeySensitiveReactionNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeyReplyNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeyReplyNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeySensitiveReplyNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeySensitiveReplyNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeyRenoteNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeyRenoteNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeySensitiveRenoteNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeySensitiveRenoteNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeyQuoteNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeyQuoteNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeySensitiveQuoteNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeySensitiveQuoteNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeyMentionNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeyMentionNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeySensitiveMentionNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeySensitiveMentionNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeyFollowNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeyFollowNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeyFollowRequestAcceptedNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeyFollowRequestAcceptedNotificationVoiceProfile>(id, cancellationToken),
                VoiceProfileType.MisskeyReceiveFollowRequestNotification => await _repository
                .GetVoiceProfile <VoiceProfile.MisskeyReceiveFollowRequestNotificationVoiceProfile>(id, cancellationToken),

                _ => throw new InvalidProgramException(),
            };

            profile.Update(data.Volume, data.Speed, data.Tone, data.Alpha, data.ToneScale, data.ComponentNormal,
                           data.ComponentHappy, data.ComponentAnger, data.ComponentSorrow, data.ComponentCalmness);

            await _repository.SaveVoiceProfile(profile, 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();
                }
            }
        }