gpt4 book ai didi

wpf - 当 ListView (WPF) 的项目更改时,如何强制屏幕阅读器 (JAWS) 朗读自定义文本?

转载 作者:行者123 更新时间:2023-12-04 12:09:23 24 4
gpt4 key购买 nike

我有一个 WPF 应用程序需要支持屏幕阅读器(尤其是 JAWS)。问题是,当 ListView 项已更改(添加、删除)时,JAWS 不会宣布任何内容。而盲人用户完全不知道发生了什么。在尝试从 ListView 控件中添加/删除项目时,我有什么方法可以强制屏幕阅读器宣布一些文本?我该怎么做?

最佳答案

如果JAWS读者不支持此功能,可以通过 SpeechSynthesizer 自行实现.语音播放示例:

using System.Speech.Synthesis;

SpeechSynthesizer MySpeechSynthesizer = new SpeechSynthesizer();
MySpeechSynthesizer.Speak("Hello!");

我用了一个 ObservableCollection 的例子分配的 ListBox . ObservableCollection是事件 CollectionChanged ,其中包含对集合执行的行为的枚举 [MSDN] :
Member name   Description
------------ ------------
Add One or more items were added to the collection.
Move One or more items were moved within the collection.
Remove One or more items were removed from the collection.
Replace One or more items were replaced in the collection.
Reset The content of the collection changed dramatically.

event将像这样实现:
// Set the ItemsSource
SampleListBox.ItemsSource = SomeListBoxCollection;

// Set handler on the collection
SomeListBoxCollection.CollectionChanged += new NotifyCollectionChangedEventHandler(SomeListBoxCollection_CollectionChanged);

private void SomeListBoxCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
// Some actions, in our case - speech
}
}

下面是我的例子:
XAML
<Window x:Class="JAWShelp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
WindowStartupLocation="CenterScreen">

<Grid>
<ListBox Name="MyListBox" DisplayMemberPath="Name" SelectedIndex="0" Width="100" Height="100" Loaded="MyListBox_Loaded" />

<WrapPanel Width="200" Height="30" Margin="40,150,0,0">
<Button Name="AddButton" Padding="5" Content="Add item" VerticalAlignment="Bottom" Click="AddButton_Click" />
<Button Name="RemoveButton" Padding="5" Margin="30,0,0,0" Content="Remove item" VerticalAlignment="Bottom" Click="RemoveButton_Click" />
</WrapPanel>
</Grid>
</Window>
Code behind
// using System.Speech.Synthesis;
// using System.Collections.ObjectModel;
// using System.Collections.Specialized;

public partial class MainWindow : Window
{
public class Person
{
public string Name
{
get;
set;
}
}

private ObservableCollection<Person> DataForListBox = new ObservableCollection<Person>();

public MainWindow()
{
InitializeComponent();
}

private void MyListBox_Loaded(object sender, RoutedEventArgs e)
{
DataForListBox.Add(new Person()
{
Name = "Peter Orange",
});

MyListBox.ItemsSource = DataForListBox;

DataForListBox.CollectionChanged += new NotifyCollectionChangedEventHandler(DataForListBox_CollectionChanged);
}

private void DataForListBox_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
SpeechSynthesizer MySpeechSynthesizer = new SpeechSynthesizer();

MySpeechSynthesizer.Speak("You are add item.");
}

if (e.Action == NotifyCollectionChangedAction.Remove)
{
SpeechSynthesizer MySpeechSynthesizer = new SpeechSynthesizer();

MySpeechSynthesizer.Speak("You are remove item.");
}
}

private void AddButton_Click(object sender, RoutedEventArgs e)
{
DataForListBox.Add(new Person()
{
Name = "Jack Rider",
});
}

private void RemoveButton_Click(object sender, RoutedEventArgs e)
{
DataForListBox.RemoveAt(1);
}
}

没有问题,可以添加 Add/Remove的复制文本元素。您也可以添加播放 .wav文件使用 PromptBuilder :
PromptBuilder MyPromptBuilder = new PromptBuilder();

MyPromptBuilder.AppendAudio("SomeFile.wav");

关于wpf - 当 ListView (WPF) 的项目更改时,如何强制屏幕阅读器 (JAWS) 朗读自定义文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17541761/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com