Foros del Web » Programación para mayores de 30 ;) » Java »

grabar voz en web (ayuda)

Estas en el tema de grabar voz en web (ayuda) en el foro de Java en Foros del Web. Hola a todos, quisiera saber como hacer una website, en la cual tenga un boton y cuando presione, grabe mi voz.. Por ejemplo asi : ...
  #1 (permalink)  
Antiguo 16/09/2010, 02:24
 
Fecha de Ingreso: diciembre-2008
Ubicación: PERU
Mensajes: 294
Antigüedad: 15 años, 4 meses
Puntos: 23
grabar voz en web (ayuda)

Hola a todos, quisiera saber como hacer una website, en la cual tenga un boton y cuando presione, grabe mi voz..

Por ejemplo asi : www.vocaroo.com

Bueno espero pistas o ideas como implementar uno .

Gracias
  #2 (permalink)  
Antiguo 18/09/2010, 07:12
 
Fecha de Ingreso: diciembre-2008
Ubicación: PERU
Mensajes: 294
Antigüedad: 15 años, 4 meses
Puntos: 23
Respuesta: grabar voz en web (ayuda)

hola alguien me podria ayudar a probar este applet.. Estoy tratando de implementarlo en <applet></applet> pero no me corre, bueno nesecito ver ejemplos acerca de mi problema (grabar voz en web) y este codigo quisiera revisarlo e ir probando .
Creditos del codigo: Pagina Fuente

Código Javascript:
Ver original
  1. package CapturarMic;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import java.io.*;
  7. import javax.sound.sampled.*;
  8.  
  9. public class CapturarMic extends JApplet{
  10.  
  11.   AudioFormat audioFormat;
  12.   TargetDataLine targetDataLine;
  13.  
  14.   final JButton captureBtn = new JButton("Capturar");
  15.   final JButton stopBtn = new JButton("Parar");
  16.  
  17.   final JPanel btnPanel = new JPanel();
  18.   final ButtonGroup btnGroup = new ButtonGroup();
  19.   final JRadioButton aiffBtn = new JRadioButton("AIFF");
  20.   final JRadioButton waveBtn = new JRadioButton("WAV",true);
  21.  
  22.   public void init( String args[]){
  23.     new CapturarMic();
  24.  
  25.   }
  26.  
  27.   public CapturarMic(){
  28.     captureBtn.setEnabled(true);
  29.     stopBtn.setEnabled(false);
  30.  
  31.     captureBtn.addActionListener(
  32.       new ActionListener(){
  33.         public void actionPerformed(
  34.                                   ActionEvent e){
  35.           captureBtn.setEnabled(false);
  36.           stopBtn.setEnabled(true);
  37.  
  38.           captureAudio();
  39.         }
  40.       }
  41.     );
  42.  
  43.     stopBtn.addActionListener(
  44.       new ActionListener(){
  45.         public void actionPerformed(
  46.                                   ActionEvent e){
  47.           captureBtn.setEnabled(true);
  48.           stopBtn.setEnabled(false);
  49.  
  50.           targetDataLine.stop();
  51.           targetDataLine.close();
  52.         }
  53.       }
  54.     );
  55.  
  56.     getContentPane().add(captureBtn);
  57.     getContentPane().add(stopBtn);
  58.  
  59.     btnGroup.add(aiffBtn);
  60.     btnGroup.add(waveBtn);
  61.  
  62.     btnPanel.add(aiffBtn);
  63.     btnPanel.add(waveBtn);
  64.  
  65.     getContentPane().add(btnPanel);
  66.  
  67.     getContentPane().setLayout(new FlowLayout());
  68.     setSize(300,220);
  69.     setVisible(true);
  70.   }
  71.  
  72.   private void captureAudio(){
  73.     try{
  74.       audioFormat = getAudioFormat();
  75.       DataLine.Info dataLineInfo =
  76.                           new DataLine.Info(
  77.                             TargetDataLine.class,
  78.                             audioFormat);
  79.       targetDataLine = (TargetDataLine)
  80.                AudioSystem.getLine(dataLineInfo);
  81.  
  82.       new CaptureThread().start();
  83.     }catch (Exception e) {
  84.       e.printStackTrace();
  85.       System.exit(0);
  86.     }
  87.   }
  88.  
  89.   private AudioFormat getAudioFormat(){
  90.     float sampleRate = 44100.0F;
  91.     int sampleSizeInBits = 16;
  92.     int channels = 1;
  93.     boolean signed = true;
  94.     boolean bigEndian = false;
  95.     return new AudioFormat(sampleRate,
  96.                            sampleSizeInBits,
  97.                            channels,
  98.                            signed,
  99.                            bigEndian);
  100.   }
  101.  
  102. class CaptureThread extends Thread{
  103.   public void run(){
  104.     AudioFileFormat.Type fileType = null;
  105.     File audioFile = null;
  106.  
  107.     if(aiffBtn.isSelected()){
  108.       fileType = AudioFileFormat.Type.AIFF;
  109.       audioFile = new File("prueba.aif");
  110.     }else if(waveBtn.isSelected()){
  111.       fileType = AudioFileFormat.Type.WAVE;
  112.       audioFile = new File("c:/test1/testfermdp.wav");
  113.     }
  114.  
  115.     try{
  116.       targetDataLine.open(audioFormat);
  117.       targetDataLine.start();
  118.       AudioSystem.write(
  119.             new AudioInputStream(targetDataLine),
  120.             fileType,
  121.             audioFile);
  122.     }catch (Exception e){
  123.       e.printStackTrace();
  124.     }
  125.   }
  126. }
  127. }

Aqui tengo otro codigo q encontre surfeando por casi toda la red.. a ver quien me da una mano..
Creditos del codigo: Pagina fuente

Código Javascript:
Ver original
  1. import java.io.File;
  2. import javax.sound.sampled.*;
  3.    
  4. public class Main {
  5.     AudioFileFormat.Type aFF_T = AudioFileFormat.Type.WAVE;
  6.     AudioFormat aF = new AudioFormat(8000.0F, 16, 1, true, false);
  7.     TargetDataLine tD;
  8.     File f = new File("Grabacion.wav");
  9.    
  10.    public Main() {
  11.    try {
  12.   DataLine.Info dLI = new DataLine.Info(TargetDataLine.class,aF);
  13.   tD = (TargetDataLine)AudioSystem.getLine(dLI);
  14.   new CapThread().start();
  15.   System.out.println("Grabando durante 10s...");
  16.   Thread.sleep(10000);
  17.   tD.close();
  18.   }catch (Exception e) {}
  19.   }
  20.   class CapThread extends Thread {
  21.  
  22.   public void run() {
  23.   try {
  24.       tD.open(aF);
  25.       tD.start();
  26.       AudioSystem.write(new AudioInputStream(tD), aFF_T, f);
  27.     }catch (Exception e){}
  28.    }
  29.   }
  30.   public static void main(String[] args) { new Main(); }
  31.   }

Etiquetas: grabar, voz
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:18.