08 ottobre
A simple ASP Translate to Speech Application/Um exemplo de Traducao com Voz em ASP
So here is a first sample application using the new service. It’s a really basic Javascript client that doesn’t do much more than formatting a string with the url and the correct parameters to invoke the T2S feature. The only thing that is remotely interesting is that this string is passed directly to the Media Player Active X, so there’s no extra work to play the wave file.
You can play with the app here: http://www.h2ktech.net/h2ktechsamples/Translate2SpeechSample.aspx (by the way, I’ll be posting all new samples to this very same location). You can ‘view source’ to check the code, or simply download it from the text file: http://www.h2ktech.net/h2ktechsamples/Translate2SpeechSample.cs.txt
The two Javascript functions work as follows:
- InvokeService builds the string based on the content of the textbox (there’s some basic filtering to emulate escaping some characters) and adds the language parameters based on the dropdown.
- PlayWave: uses the iframe as a container and creates a document on the fly with references to the Media Player Active X. It also adds a regular http link (like the ones in the previous blog post) in case the users doesn’t have (and doesn’t want to install) the control.
Here’s a good reference on embedding Media Active X controls: http://cit.ucsf.edu/embedmedia/step3.php
Give it a try, and feel free to play with the code – just don’t use it for any commercial application alright?
Cheers,
Helvecio
English - Portuguese
Aqui está um primeiro exemplo de um aplicativo usando o novo serviço. É um programa realmente básico em JavaScript que não faz muito mais do que formatar uma string com a url e os parâmetros corretos para invocar o recurso de T2S. A única coisa que é remotamente interessante é que esta string é passaao diretamente para o Active X do Media Player, portanto, não há nenhum trabalho extra para reproduzir o arquivo wave.
Você pode brincar com o aplicativo aqui: http://www.h2ktech.NET/h2ktechsamples/Translate2SpeechSample.aspx (a propósito, eu vou colocar todos os code samples neste mesmo local daqui para frente). Você pode 'Exibir fonte' para ler o código, ou simplesmente o download do arquivo de texto:http://www.h2ktech.NET/h2ktechsamples/Translate2SpeechSample.cs.txt
As duas funções de JavaScript funcionam da seguinte forma:
- InvokeService constrói a cadeia de caracteres com base no conteúdo da caixa de texto (adicionei alguns filtros básicos para emular escaping alguns caracteres) e adicionar os parâmetros de idiomas com base na lista.
- PlayWave: utiliza o iframe como um recipiente e cria um documento com referências para o Media Player ACTIVEX. Também adiciona um link http normal (como aqueles na postagem do blog anterior), caso os usuários não tenham (e não queiram instalar) o controle.
Aqui está uma boa referência sobre a incorporação de controles Active X de mídia: http://Cit.ucsf.edu/embedmedia/step3.php
Experimente e sinta-se a vontade para brincar com o código – só não use em nenhum aplicativo comercial ok?
[]s,
Helvecio