Hi makumbi,
Please refer below code.
HTML
<asp:GridView ID="gvCustomer" runat="server" AutoGenerateColumns="False" Width="405px">
<Columns>
<asp:BoundField DataField="CustomerId" HeaderText="CustomerId" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button Text="View" runat="server" OnClick="OnViewDetails" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<input id="text" runat="server" />
<button onclick="talk()">
Talk It!</button>
<asp:Button OnClick="OnListen" runat="server" Text="Voice" OnClientClick="listen()" />
<select id="Language">
<option value="en">English</option>
<option value="fr">French</option>
</select>
<script src="webspeech-master/src/webspeech.js" type="text/javascript"></script>
<script type="text/javascript">
var speaker, listener;
window.onload = function () {
AudioListener
ws = webSpeechNoConflict();
try {
speaker = new ws.Speaker();
speaker.onEnd(function () {
console.log('just finished talking...');
});
}
catch (ex) {
console.log(ex);
speaker = null;
document.getElementById("status").innerHTML = ex;
}
try {
listener = new ws.Listener();
}
catch (ex) {
console.log(ex);
listener = null;
document.getElementById("status").innerHTML = ex;
}
};
function talk() {
if (speaker) {
speaker.speak(document.getElementById("Language").value, document.getElementById("text").value);
}
}
function listen() {
if (listener) {
listener.listen(document.getElementById("Language").value, function (text) {
document.getElementById("text").value = text;
});
}
}
function MyFunction(num) {
var term = num;
var voices = window.speechSynthesis.getVoices();
var speech = new SpeechSynthesisUtterance();
speech.voice = voices[2];
speech.rate = 1;
speech.pitch = 100;
speech.text = term;
speechSynthesis.speak(speech);
return false;
}
</script>
Namespace
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("CustomerId"),
new DataColumn("Name"),
new DataColumn("Country")});
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
gvCustomer.DataSource = dt;
gvCustomer.DataBind();
}
}
protected void OnViewDetails(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
string customerId = row.Cells[0].Text;
string name = row.Cells[1].Text;
string country = row.Cells[2].Text;
string message = "\\nCustomerId: " + customerId + "\\nName: " + name + "\\nCountry: " + country;
text.Value = customerId;
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + message + "');", true);
}
protected void OnListen(object sender, EventArgs e)
{
int num = Convert.ToInt16(text.Value);
ClientScript.RegisterStartupScript(this.GetType(), "alert", "MyFunction('" + num + "');", true);
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {
New DataColumn("CustomerId"),
New DataColumn("Name"),
New DataColumn("Country")})
dt.Rows.Add(1, "John Hammond", "United States")
dt.Rows.Add(2, "Mudassar Khan", "India")
dt.Rows.Add(3, "Suzanne Mathews", "France")
dt.Rows.Add(4, "Robert Schidner", "Russia")
gvCustomer.DataSource = dt
gvCustomer.DataBind()
End If
End Sub
Protected Sub OnViewDetails(ByVal sender As Object, ByVal e As EventArgs)
Dim row As GridViewRow = TryCast(TryCast(sender, Button).NamingContainer, GridViewRow)
Dim customerId As String = row.Cells(0).Text
Dim name As String = row.Cells(1).Text
Dim country As String = row.Cells(2).Text
Dim message As String = "\nCustomerId: " & customerId & "\nName: " & name & "\nCountry: " & country
text.Value = customerId
ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('" & message & "');", True)
End Sub
Protected Sub OnListen(ByVal sender As Object, ByVal e As EventArgs)
Dim num As Integer = Convert.ToInt16(text.Value)
ClientScript.RegisterStartupScript(Me.GetType(), "alert", "MyFunction('" & num & "');", True)
End Sub